Timer: 4 min, like in an interview. Hints and autocomplete are off while it runs
Required fields
EasyJSON 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.
Examples
missingFields({ id: 1, price: 500 }, ['id', 'title', 'price'])Returns [ 'title' ]
missingFields({ id: 0, title: '' }, ['id', 'title'])Returns []
Asked at Avito · Source
Loading the editor...
- Input
missingFields({ id: 1, price: 500 }, [ 'id', 'title', 'price' ])Expected[ 'title' ] - Input
missingFields({ id: 0, title: '' }, [ 'id', 'title' ])Expected[] - Input
missingFields({}, [ 'id', 'title' ])Expected[ 'id', 'title' ]
Hidden tests run on Submit