I’m trying to understand how the “Wherefore art thou” problem works. I can’t wrap my head around the whole code and how this works. I’ve read the hint and solution and I still don’t get it.
function whatIsInAName(collection, source) {
// What’s in a name?
var arr = [];
// Only change code below this line
var srcKeys = Object.keys(source);
return collection.filter(function(obj) {
for (var i = 0; i < srcKeys.length; i++) {
if (!obj.hasOwnProperty(srcKeys[i]) || obj[srcKeys[i]] !== source[srcKeys[i]]) {
return false;
}
}
return true;
});
// Only change code above this line
}
whatIsInAName([{ first: “Romeo”, last: “Montague” }, { first: “Mercutio”, last: null }, { first: “Tybalt”, last: “Capulet” }], { last: “Capulet” });