Can someone please explain this to a layman. I really don’t understand the basic solution of the Wherefore Art Thou challenge. Specifically, I don’t understand this block of code
return collection.filter(function(obj){
for(var i=0;i<srcK.length;i++){
if(!obj.hasOwnProperty(srcK[i]) || obj[srcK[i]] !== source[srcK[i]]){
return false;
}
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
//Object.keys finds the property for a given object(all listed)
var srcK = Object.keys(source);
// Only change code above this line
return collection.filter(function(obj){
for(var i=0;i<srcK.length;i++){
if(!obj.hasOwnProperty(srcK[i]) || obj[srcK[i]] !== source[srcK[i]]){
return false;
}
}
return true;
});
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
This is all of the code, but the above is what I’m confused about.
(!obj.hasOwnProperty(srcK[i]) || obj[srcK[i]] !== source[srcK[i]]) this specifically. I know it’s supposed to return false, but I don’t understand the syntax
The syntax is saying if the object does not (!) have property srK[i] OR the value of obj[srcK[i]] is not equal to the value of source[srcK[i]]).