Return objects that match every key in a criteria object
You are presented with a task involving a dataset represented as an array of objects, where each object delineates a person’s attributes, such as name, company, position, and level. Additionally, there is a match object specifying criteria to identify matches based on specific attributes. Your challenge is to develop a function, findMatches, which filters the dataset to return only the objects that meet all the criteria outlined in the match object. To filter matching JSON objects, Array.prototype.filter() and Object.entries() are the main tools.
The core objective is to write a program that, given the dataset and the match object, produces an array containing only the objects that satisfy all the criteria in the match object. For instance:
Input:
data: [
{ name: 'John', company: 'Google', position: 'Software Engineer', level: 'Entry' },
{ name: 'Ann', company: 'Waymo', position: 'Product Manager', level: 'Entry' }
]
match: { position: 'Product Manager', level: 'Entry' }
Output:
[
{ name: 'Ann', company: 'Waymo', position: 'Product Manager', level: 'Entry' }
]
This exercise tests your ability to manipulate complex data structures and implement effective filtering algorithms, essential skills in data handling and software development. It involves traversing arrays, understanding object properties, and applying logical operations to achieve the desired outcome.