*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
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