Intermediate Algorithm Scripting1: Wherefore art thou

Tell us what’s happening:

please tell me where i am wrong. I only passed 2/4.

Your code so far


function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
let a=Object.keys(source);
for(let i=0;i<collection.length;i++){
for(let j=0;j<a.length;j++){
  if(collection[i].hasOwnProperty(a[j]) && collection[i][a[j]]===source[a[j]]){
    arr.push(collection[i]);
  }
}
}
console.log(arr);
// 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/83.0.4103.97 Safari/537.36.

Challenge: Wherefore art thou

Link to the challenge: