Tell us what’s happening:
Hello,
This challenge was particularly… challenging for me. I generally don’t look at the answers unless I am completely out of options, but this time I broke down after about an hour working on it and half a day mulling it over.
I understand the basic logic I think.
But why doesn’t this work?
let key = Object.keys(source)
return collection.filter(Obj => {
for (let i = 0; i < key.length; i++){
if (Obj.hasOwnProperty(key[i]) && Obj[key[i]] == source[key[i]]){
return true;
}
}
})
It seems like this is a rather simple type of problem, but I really was stumped. I’m not discouraged but I am worried my understanding is severly lacking.
Thank you for your time! Below is the solution that was accepted (I had to look it up).
**Your code so far**
function whatIsInAName(collection, source) {
// Only change code below this line
const key = Object.keys(source)
return collection.filter(Obj => {
for (let i = 0; i < key.length; i++){
if (!Obj.hasOwnProperty(key[i]) || Obj[key[i]] !== source[key[i]]){
return false;
}
}
return true;
})
}
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/101.0.4951.67 Safari/537.36
Challenge: Wherefore art thou
Link to the challenge: