So this is my code below for this challenge. It passes every test except this one:
whatIsInAName([{ “a”: 1, “b”: 2 }, { “a”: 1 }, { “a”: 1, “b”: 2, “c”: 2 }], { “a”: 1, “c”: 2 }) should return [{ “a”: 1, “b”: 2, “c”: 2 }]. It returns an extra {“a”:1} in my answer. I am convinced something is wrong with the site at the moment because whenever I try to return the statement inside the last if, it prints false, which means that this extra {“a”: 1} should not be printed.
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var sourceKeys = Object.keys(source);
var count = 0;
for(var j = 0; j < collection.length; j++){
for(var i = 0; i < sourceKeys.length; i++){
if(collection[j].hasOwnProperty(sourceKeys[i])){
if(collection[j][sourceKeys[i]] == source[sourceKeys[i]]){
count++;
}
}
if(count == sourceKeys.length){
arr.push(collection[j]);
count = 0;
}
}
}
// Only change code above this line
return arr;
}