返回collection内对象包含source对象内所有属性,并且值相等
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
collection.forEach((cur) => {
var has = true;
Object.keys(source).forEach((c) => {
if (source[c] !== cur[c]) {
has = false;
}
});
if (has === true) {
arr.push(cur);
}
});
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });