Tell us what’s happening:
I don’t understand why this code doesn’t work for this problem. Can someone help me understand? The goal is to return an array that contains all objects with the second argument passed to the function.
**Your code so far**
function whatIsInAName(collection, source) {
const arr = [];
// Only change code below this line
return collection.filter(name => name.hasOwnProperty(source));
// Only change code above this line
}
console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36
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.
source is an object. You want to find all of the objects in the array that have all of the same properties that source has, and those properties must be set to the same values.
Ok so I see to an extent. I need to find the objects that contain the mentioned property, so in the example that would be “last”, with those properties set to the same values. Can you explain why my code above doesn’t work for that?