Tell us what’s happening:
I’ve been stuck on this particular challenge. I finally gave up and watched a video of someone working through it. I thought I understood what their code was doing so I recreated it line by line but it wouldn’t pass either. I then tried the attempt below. It passes the first two requirements but fails the last four. I tried putting it into a visualizer tool, but still can’t make heads nor tails of what’s going on.
Your code so far
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
let keys = Object.keys(source);
//console.log(source[keys[0]])
//console.log(collection[2][keys[0]])
//console.log(collection[0].hasOwnProperty(keys[0]))
for (let i = 0; i < collection.length; i++) {
for (let j = 0; j <= keys.length; j++) {
if (collection[i].hasOwnProperty(keys[j]) && collection[i][keys[j]] === source[keys[j]]){
arr.push(collection[i]);
}
}
}
// Only change code above this line
return arr;
}
whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 });
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
.
Challenge: Wherefore art thou
Link to the challenge: