function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
arr=collection.filter(el=>el.hasOwnProperty(Object.keys(source))&&el[Object.keys(source)]==Object.values(source));
return arr;
}
i think this is only checking for first property of source object.
collection is array of objects
*el // is referencing to these objects
*Object.keys(source) //it is an array having the properties of object source.
and similarly
*Object.values(source) // stores the values of object source.
*el[Object.keys(source)] // this will return the value of the property from el object.
el[Object.keys(source)] == Object.values(source)//this is checking
el[name of property of source object] == the value of that property.
m i right??
That part attempts to compare a single value to an array (Object.values(source)). Remember that Object.keys(source) is also an array, so writing el[Object.keys(source)]) makes no sense.
You should add some console.log statements to see what the values are of each before continuing.
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
arr=collection.filter(el=> {
console.log(el[Object.keys(source)]);
console.log(Object.values(source));
console.log();
return el.hasOwnProperty(Object.keys(source)) && el[Object.keys(source)]==Object.values(source);
});
return arr;
}
console.log(whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 }));