function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
//return Object.keys(source);
var sourceKeys = Object.keys(source);
var sourceValues = Object.values(source);
for(var i=0; i<collection.length; i++){
var collectionKeys = Object.keys(collection[i]);
var collectionValues = Object.values(collection[i]);
var allKeysTrue = true;
var allValuesTrue = true;
for(var j=0; j<sourceKeys.length; j++){
if(!collectionKeys.toString().includes(sourceKeys[j].toString())){
allKeysTrue = false;
}
if(!collectionValues.toString().includes(sourceValues[j].toString())){
allValuesTrue = false;
}
}
if(allKeysTrue && allValuesTrue){
arr.push(collection[i]);
}
}
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
No comments:
Post a Comment