I see that hasownvals is not a method, however I don’t see how using hasownproperty is useful. Also why would i refer to Object.keys when the key isn’t important here, is it?
Your code so far
function whatIsInAName(collection, source) {
// "What's in a name? that which we call a rose
// By any other name would smell as sweet.”
// -- by William Shakespeare, Romeo and Juliet
const sourceVals = Object.values(source);
// filter the collection
return collection.filter(obj => {
for (let i = 0; i < sourceVals.length; i++) {
if (!obj.hasOwnValues(sourceVals[i]) ||
obj[sourceVals[i]] !== source[sourceVals[i]]) {
return false;
}
}
return true;
});
}
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/113.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Wherefore art thou
Link to the challenge: