Help with the code

Help with the code
0

#1

Tell us what’s happening:

Why does my filter function doesn’t work?Any suggestions.
thanks.

Your code so far

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr=[];
  // Only change code below this line
  var cnt=0;
arr=collection.filter(function(obj)
    {
    
    var objkeys=Object.keys(obj);
    var sourcekeys=Object.keys(source);
    for(var i=0;i<sourcekeys.length;i++)
      {
        if(objkeys.indexOf(sourcekeys[i])!=-1)
          {
            cnt++;
          }
      }
    if(cnt==sourcekeys.length)
      {
        cnt=0;
         var objvalues=Object.values(obj);
    var sourcevalues=Object.values(source);
        for(var j=0;i<sourcevalues.length;j++)
      {
        if(objvalues.indexOf(sourcevalues[i])!=-1)
          {
            cnt++;
          }
      }
        if(cnt==sourcevalues.length)
          {
            return true;
          }
        else
          return false;
      }
   return false;
    
  });
  
  // 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:


#2

In your code below, you use a variable called j in your for loop, but then reference variable i in several places. Do you think you should be using j or i?

for(var j=0;i&lt;sourcevalues.length;j++)
  {
    if(objvalues.indexOf(sourcevalues[i])!=-1)
      {
        cnt++;
      }
  }

#3

Thanks for your help.