After a lot of failed attempts and reading of other forum posts I managed to solve this problem…I would like to check that I am understanding exactly how this program works. I have put comments in describing what I think is happening - am I correct? Have I missed anything?
if you want someone to look at your code, it is polite to not give a screenshot, but to give the link to a repl or codepen or something or just paste the code.
I mean, if someone wanted to copy and paste your code to check it is working in the right way, how would that be possible like this?
My apologies, I wasn’t aware… Here is a copy and paste of the above:
function whatIsInAName(collection, source) {
var sourceKey = Object.keys(source); // returns an array which can be compared with collection. Necessary because an object can’t be compared to an array.
return collection.filter(function(obj) { //this returns the filtered array. The collect is parsed as obj.
return sourceKey.every(function(key) { //this determines what is filtered out. array.every() test whether all elements pass a test. The sourceKey array is parsed to the function as key.
return obj.hasOwnProperty(key) && obj[key] == sourceKey; //this is the test provided to the every function and it checks whether obj (collection) has the property (sourceKey) AND that the elements are identical
})