const intersection = (a, b) => {
const s = new Set(b);
return [...new Set(a)].filter(x => s.has(x));
};
intersection([1, 2, 3], [4, 3, 2]); // [2, 3]
更多 数据交集、并集及对象相关方法合集
使用ES6求两个数组(简单数组或对象数组)的并集,交集和差集
const intersection = (a, b) => {
const s = new Set(b);
return [...new Set(a)].filter(x => s.has(x));
};
intersection([1, 2, 3], [4, 3, 2]); // [2, 3]
更多 数据交集、并集及对象相关方法合集
使用ES6求两个数组(简单数组或对象数组)的并集,交集和差集