Not really sure why it will pass the first two tests and then return and empty array on the 3rd test. I know just by looking at some of the other solutions there are more elegant ways of doing this but by following the logic I wrote, I cannot understand what the difference in outcome was between the second test (which also returns more than one object) and the third test.
Your code so far
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
for (var i = 0;i < collection.length;i++) {
if (collection[i].hasOwnProperty(Object.keys(source))) {
for (var j in collection[i]) {
if (collection[i][j] === source[j]) {
arr.push(collection[i]);
}
}
}
}
// Only change code above this line
return arr;
}
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/wherefore-art-thou