Facebook | Phone screen | 2021 | Filter items by array of rules
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2021-01-21Added By Anonymous
Source: Link
Company: Meta (Facebook)
Role: e3
Interview Stage: Phone screen
Location: unknown
Year: 2021
Original Post Content:
Given an array of items `arr`const arr = [
{type: 'phone', color: 'green', name: 'iPhone'},
{type: 'phone', color: 'gold', name: 'Samsung'},
{type: 'computer', color: 'silver', name: 'Chromebook'},
];And rules
const rules = [
{k: 'name', v: 'iPhone'},
{k: 'color', v: 'gold'},
];Filter the elements from the items array with rules from the rules array.
example output:
[
{type: 'computer', color: 'silver', name: 'Chromebook'},
]