Please can some help explain the answer to me

*Really need help understanding how the code answer is comparing the values of the arrays and not just the keys. Im super stuck and finding all of the challenges in this section really difficult. I result in having to look at the answer after hours of trying and failing :frowning: turns out most of the time im on an incorrect path to what the answer is.

function whatIsInAName(collection, source) {
const arr = ;
// Only change code below this line

var srcKeys = Object.keys(source);

i thought we would want to compare the values, not the keys? The way i read this is that im returning the object key which is ‘last’ and then going on to compare if the collection array contains ‘last’…
console.log(srcKeys[0]) // prints: last
This makes no sense to me…

return collection.filter(function(obj) {
for (var i = 0; i < srcKeys.length; i++) {
if (
!obj.hasOwnProperty(srcKeys[i]) ||

if obj hasOwnProperty(last[0]) - Wouldn’t this mean that it would be true? since they all have a ‘last’ property’

obj[srcKeys[i]] !== source[srcKeys[i]]

or if obj[last[0] !== { last: “Capulet” }[last[0]} - ?? I cant even work out what this is comparing

WHERE ABOUTS IN THIS CODE IS IT COMPARING “Capulet” IN collection, TO “Capulet” IN source, IN ORDER TO RETURN TRUE OR FALSE?

) {

return false;
}
}
return true;
});
}

console.log(whatIsInAName([{ first: “Romeo”, last: “Montague” }, { first: “Mercutio”, last: null }, { first: “Tybalt”, last: “Capulet” }], { last: “Capulet” }));





      **Your browser information:**

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36</code>

**Challenge:**  Wherefore art thou

**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou

You are comparing both. You don’t know what the property names on the objects will be in advance. Yes, for the first example you are looking for the “last” property. But in the second example you are looking for the “apple” property. So first you have to check if the property names match and then you have to check if the values for those property names match.

Just as an FYI.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).