大家早上好。请问这段代码有什么问题?我已经在stackoverflow上尝试过关于重复条目的所有解决方案,但是没有任何效果。这是代码。
function whatIsInAName(collection, source) {
const [[findKey, findVal]] = Object.entries(source);
return collection.filter(el => (
Object.entries(el).some(([key, val]) => (
key === findKey && val === findVal
)
)))
}
console.log(
whatIsInAName([{
first: "Romeo",
last: "Montague"
}, {
first: "Mercutio",
last: null
}, {
first: "Tybalt",
last: "Capulet"
}, {
first: "another",
last: "Capulet"
}, {
first: "Tybalt",
last: "notACapulet"
}], {
last: "Capulet"
})
);