Hello guys I have been working on this challenge form FCC here is the Link
this is the challenge
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
For example, if the first argument is
[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }],
and the second argument is{ last: "Capulet" },
then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument.
this is my code so far
function whatIsInAName(collection, source) {
var arr = [];
let propFinder = Object.keys(source);
// Only change code below this line
collection.map(x=>{
if(x[propFinder] === source[propFinder]){
arr.push(x)
}
})
// Only change code above this line
return arr;
}
// this one does not match
whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 });
// expected output { "apple": 1, "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }]
// but this this one match
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" })
// expected output [{ first: "Tybalt", last: "Capulet" }]