i try a similar condition like you and do not get two cases, i understand but i am not sure why my code not pass all cases
function whatIsInAName(collection, source) {
// What's in a name?
let arr = [];
// Only change code below this line
let dataKeys = Object.keys(source);
let dataValues = Object.values(source);
for(let index = 0; index < dataKeys.length ; index++) {
arr = collection.filter( (elem) => {
//console.log(elem[dataKeys[index]]);
return ((elem[dataKeys[index]] === dataValues[index]) && (collectionKeys.length >= dataKeys.length));
});
}
// Only change code above this line
console.log(arr);
return arr;
}
whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 });
the case not pass are:
whatIsInAName([{ “apple”: 1, “bat”: 2 }, { “bat”: 2 }, { “apple”: 1, “bat”: 2, “cookie”: 2 }], { “apple”: 1, “bat”: 2 })should return
[{ “apple”: 1, “bat”: 2 }, { “apple”: 1, “bat”: 2, “cookie”: 2 }]
whatIsInAName([{ “apple”: 1, “bat”: 2 }, { “apple”: 1 }, { “apple”: 1, “bat”: 2, “cookie”: 2 }, { “bat”:2 }], { “apple”: 1, “bat”: 2 })should return
[{ “apple”: 1, “bat”: 2 }, { “apple”: 1, “bat”: 2, “cookie”:2 }]