Code Lab

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

Required fields

FácilJSON and data4 min

An API returned an ad item, and the array required lists the fields it must have. Write a function missingFields(item, required) that returns an array of the fields from required that item does not have, in the order of required.

Exemplos

missingFields({ id: 1, price: 500 }, ['id', 'title', 'price'])

Retorna [ 'title' ]

missingFields({ id: 0, title: '' }, ['id', 'title'])

Retorna []

A field is there even when its value is empty.

Cobrada em Avito · Fonte

Carregando o editor...
  1. EntradamissingFields({ id: 1, price: 500 }, [ 'id', 'title', 'price' ])
    Esperado[ 'title' ]
  2. EntradamissingFields({ id: 0, title: '' }, [ 'id', 'title' ])
    Esperado[]
  3. EntradamissingFields({}, [ 'id', 'title' ])
    Esperado[ 'id', 'title' ]

Os testes ocultos rodam no envio