## Wherefore art thou

Tell us what’s happening:
Why this code does not return the correct answer. Is it related to equality check if so can anyone please explain in detail what’s going on in this code to make it irrect

Your code so far


function whatIsInAName(collection, source) {

let srckey = Object.keys(source)

return collection.filter((obj)=>{ 
for(let i=0; i<srckey.length; i++){
if(obj.hasOwnProperty(srckey[i]) || obj[srckey[i]] === source[srckey[i]]) {
  return true
}
}
return true
})
}

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



Your browser information:

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

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

Check this line
Do you have any case in which is it false?
Notice that you are using a || which is an OR operator

Also, in the case you have posted srckey has one element only and so it works, but if you have more elements in that, with the way your loop is written it will just check the first element in that array

And if that part in the if statement is not executed, then it will just return true anyway (last line of the callback inside the filter method)
Actually, no filtering is done

1 Like

Wow mindfull thanks so much

Sorry, missed a piece there
with the way your loop is written it will just check the first element in the array and then if that check results true it will not check the other elements (but it could be false for the others!)