Tell us what’s happening:
I guess mistake somewhere in the if condition, can’t figure out where exactly.
It’s working for first two test cases, for others… it’ giving too big input, like checks are not strict enough, I can’t understand why checks are not strict enough.
**Your code so far**
function whatIsInAName(collection, source) {
let arr = [];
// Only change code below this line
for (let item of collection) { // need for.. of >>> it's array of objects
for (let key of Object.keys(source)) { //need for... of >>> it's array
if (!item.hasOwnProperty(key) || item[key] != source[key]) {
break;
}
arr.push(item);
}
}
// Only change code above this line
//console.log(arr);//tests only
return arr;
}
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/103.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Wherefore art thou
Link to the challenge: