Tell us what’s happening:
filter method works but couldn’t do it without higher order function.
Your code so far
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
let key=Object.keys(source);
let ckey=Object.keys(collection);
for(let i in collection){
if(collection[i].hasOwnProperty(key[i])&&collection[i][key[i]]==source[key[i]]){
arr.push(collection[i]);
}
}
// Only change code above this line
return arr;
}
console.log(JSON.stringify(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 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
.
Link to the challenge: