Tell us what’s happening:
Hi, I copy-pasted Solution 1 provided in the Challenge Guide. I can’t understand why the code doesn’t work if I replace the || symbols in line 7 with &&. I also want to know what’s the opposite of:
if (!obj.hasOwnProperty(sourceKeys[i]) ||
obj[sourceKeys[i]] !== source[sourceKeys[i]])
It seems to me that it should be the following but it doesn’t work:
if(obj.hasOwnProperty(sourceKeys[i]) &&
obj[sourceKeys[i]] === source[sourceKeys[i]])
**Your code so far**
function whatIsInAName(collection, source) {
let sourceKeys = Object.keys(source);
// Only change code below this line
return collection.filter(actor => {
for (let i = 0; i < sourceKeys.length; i++) {
if (!actor.hasOwnProperty(sourceKeys[i]) || actor[sourceKeys[i]] !== source[sourceKeys[i]]) {
return false;
}
}
return true;
});
}
// Only change code above this line
console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36
Challenge: Wherefore art thou
Link to the challenge: