Code Lab

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

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.

Ejemplos

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

Devuelve [ 'title' ]

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

Devuelve []

A field is there even when its value is empty.

Preguntada en Avito · Fuente

Cargando el 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' ]

Las pruebas ocultas se ejecutan al enviar