Help Only passes 3 out of 6 test cases Wherefore art thou

Tell us what’s happening:
Only passes 3 out of 6 test cases(trying without higher order functions)

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)&&collection[i][key]==source[key]){
      arr.push(collection[i]);
    }
  }
  
  // Only change code above this line
  return arr;
}

console.log(JSON.stringify(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 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:

What do the failing tests say?

This happens because the second argument (source) can be an array to, with many keys and values. Currently you test every object in the collection with one key and its value. You must do the same but with every possible key and value from the source.

Tell us what’s happening:
Made it worse

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou/