Intermediate Algorithm Scripting - Wherefore art thou

Tell us what’s happening:
Describe your issue in detail here.
Pls, what is wrong in my code???
Your code so far

function whatIsInAName(collection, source) {
const newArr = [];
for (let i = 0; i < collection.length; i++) {
  for (let prop in source) {
    if (collection[i][prop] == source[prop]) {
      newArr.push(collection[i])
    }
  }
}
return newArr
}

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/115.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Wherefore art thou

Link to the challenge:

Did you try running the test cases and console logging the result? I ask because you should see something funky -

Every single time you find one source that matches, you want to push a reference to the current collection object?

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