Intermediate Algorithm Scripting - Wherefore art thou

Tell us what’s happening:
When I run this code I am getting my array back. I know my if statement is comparing undefineds but I can’t seem to figure out how to compare each individual object with the source object. Any suggestions?

Your code so far

function whatIsInAName(collection, source) {
  return collection.filter(function(item) {
    const key = Object.keys(source).toString;
    if(item[key] === source[key]){
      return item;

console.log(whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 }));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Intermediate Algorithm Scripting - Wherefore art thou

Link to the challenge:

const key = Object.keys(source).toString;

Do you mean this ?

const key = Object.keys(source).toString();

Yes, that is what I mean.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.