What is wrong with my logic, please explain. It works for the first 3 case, but not the last. I can’t seem to figure out what is wrong with this. Please advise:
This is my first time asking for help, so don’t really know how to post code for review.
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var checkKeys = Object.keys(source);
for (var i = 0; i < checkKeys.length; i++){
for (var j=0; j<collection.length; j++){
if (collection[j].hasOwnProperty(checkKeys[i]) && collection[j][checkKeys[i]] === source[checkKeys[i]]){
if (collection[j].hasOwnProperty(checkKeys[i+1]) && collection[j][checkKeys[i+1]] === source[checkKeys[i+1]]){
break;
}
arr.push(collection[j]);
}
}
}
// Only change code above this line
return arr;
}