How to approach further with Wherefore art thou?

How to approach further with Wherefore art thou?
0

#1

The 1st two tests are running but the 3rd and 4th are not . This doesn’t work where the source has two or more iterations.
Please help as to how i should approach further .Thanks in advance.

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var x=Object.keys(source);
 
  //var y=source.hasOwnProperty(x);
  for(var i=0;i<collection.length;i++){
    if(collection[i].hasOwnProperty(x)){
     if(collection[i][x]==source[x]){
       arr.push(collection[i]);
     }
    }
  }
  
  // Only change code above this line
  return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:


#2

Check the link given for Object.keys. You’ll find that it returns an array of strings. Yet you use it like as if it were a single string.

I’d rename x to something like keys to remind yourself that it’s an array of several values and that you need to go through all of them individually just like you go through all the items in collection.