Code Lab

Mode entretien. Minuteur de 4 min, sans indices ni autocomplétion

Required fields

FacileJSON 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.

Exemples

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

Renvoie [ 'title' ]

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

Renvoie []

A field is there even when its value is empty.

Posé chez Avito · Source

Chargement de l'éditeur...
  1. EntréemissingFields({ id: 1, price: 500 }, [ 'id', 'title', 'price' ])
    Attendu[ 'title' ]
  2. EntréemissingFields({ id: 0, title: '' }, [ 'id', 'title' ])
    Attendu[]
  3. EntréemissingFields({}, [ 'id', 'title' ])
    Attendu[ 'id', 'title' ]

Les tests cachés se lancent à la soumission