I solved all the intermediate algorithms,still cant solve this

Tell us what’s happening:
I am done.I am just burned maybe i don’t know.I left this for the end since i had hard times to solve it.I managed to solve all the others through search and ask,but this one is still pain in my ass.It is working fine for the first two tests but then it doesn’t,and i know it doesn’t work because i should do something to iterate through all keys Array and check if each property of the object contains all of them,i just DON’T KNOW how to do it. I saw the recommended solutions but still i cant quite understand it.I will leave it for now,if someone can come up and explain this to me like i was 5 years old,i would appreciate it!Thanks for your time!

Your code so far


function whatIsInAName(collection, source) {
var arr = [];

let keys = Object.keys(source);

arr=collection.filter(item=>item[keys]==source[keys]);

console.log(arr);
  
return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 });
whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 });


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36.

Challenge: Wherefore art thou

Link to the challenge:

Can you walk us through your algorithm (not the code). Explain the steps you believe are necessary to solve this problem. Once you have developed the correct algorithm for the challenge, then writing the code is much easier.

1 Like

So i create a variable keys which contains all the keys of the second parameter. Then i wanna iterate each element of the array (first argument the function accepts) and check if each element contains all the keys of the array keys i created before and they have the same value.If it does,i wanna push it to an array,if it doesn’t i want to skip it.Do i think of this right?