Wherefore art thou algorithm challange

Hi Everyone,

Completely lost and confused. I can’t figure out how to match the source property to the collection. I feel like my brain is completely stuck. please help

Thanks!

Your code so far

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  
  
  // Only change code above this line
  function matchingWord(value){
    return value == source;
  }
  var match = collection.filter(matchingWord);
  return match;
}

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

Link to the challenge:
https://www.freecodecamp.org/challenges/wherefore-art-thou

I want to user a for loop to loop through the collection using Object.keys(source). Then i want to compare the source key with the collection keys, if it matches i want to push it to an array. Below is what i have so far but not sure if i’m writing it the correct way still feel lost.


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

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