Wherefore art thou whats wrong i n this code

Wherefore art thou whats wrong i n this code
0.0 0

#1

Tell us what’s happening:

Your code so far


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

console.log(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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou


#2

n is a key of an object and source is an object. Therefore, n === source doesn’t make sense. Also, the actual comparison has to be done with values of objects.