Code Lab

Modo entrevista. Cronômetro de 3 min, sem dicas e sem autocompletar

Count the keys

FácilObjects3 min

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

Exemplos

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

Retorna 2

count({})

Retorna 0

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

Retorna 2

An empty string and zero are values of properties too.

Fonte

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

Os testes ocultos rodam no envio