Intermediate Algorithm Scripting: Wherefore art thou

Intermediate Algorithm Scripting: Wherefore art thou
0

#1

Tell us what’s happening:
I don’t know how to solve this. I’ve been on this test for far too long. Can someone help?

Your code so far


function whatIsInAName(collection, source) {

  var sourceKeys = Object.keys(source);
  var arr = collection.filter(function (val, j){
    
    
    return val.hasOwnProperty(sourceKeys[j]) === true && val[sourceKeys[j]] === source[sourceKeys[j]];
      
    
  });

 return arr;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0.

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


#2

First, I think you need to add a console.log statements like below on a line before the return statement. You will need to use your browser’s console (Ctrl+Shft+J in Chrome) to be able to see what is displayed and then click on the arrays to see the arrays’ contents. This will at least show you what your current code is returning.

  console.log('source = ' + JSON.stringify(source))
  console.log(arr)

See if this gives you some insight or at least allow you to ask more specific questions about what you do not understand regarding the results or the challenge expectations.


#3

Ok, I think I get it. You have to iterate the source keys, so I have to for-loop the sourceKeys???


#4

There are various ways to loop through the sourceKeys and a for loop is one of them.