I had trouble on this on as well. Let me break your function into the steps it is solving.
function whatIsInAName(collection, source) {
const arr = []; // return array
const sourceKeys = Object.keys(source) // you can't access
// the properties on an object without you knowing the keys
// so you make an array of the keys
for(let i = 0 ; i < collection.length; i++) { //look through the
// collection to search all the objects
for(let j = 0; j < sourceKeys.length; j++){ // searching
//through all the keys to check that they all fit
const sourceKey = source[sourceKeys[j]]
if(collection[i][sourceKeys[j]] === sourceKey) {
// see if the key exists
arr.push(collection[i]) // push to answer array
}
}
}
console.log(arr);
return arr;
}
This works only to see if the key is in the object:
Each name and value pair of the source object has to be present
in the object.
Some helpful functions.
Object.entries(source) // returns an array of the key value pairs
// ordered like this [[key, value], [key2, value2], etc]
Object.values(source) // returns an array of values