Code Lab

Modo entrevista. Temporizador de 3 min, sin pistas y sin autocompletado

Count the keys

FácilObjects3 min

Write a function count(obj) that returns the number of properties of the object obj.

Ejemplos

count({ name: 'John', age: 30 })

Devuelve 2

count({})

Devuelve 0

count({ name: '', age: 0 })

Devuelve 2

An empty string and zero are values of properties too.

Fuente

Cargando el editor…
  1. Entradacount({ name: 'John', age: 30 })
    Esperado2
  2. Entradacount({})
    Esperado0
  3. Entradacount({ name: '', age: 0 })
    Esperado2

Las pruebas ocultas se ejecutan al enviar