let a = [1, 2, 3];
let b = [3, 5, 2];
// 交集
let intersection = a.filter(x => b.includes(x));
// 打印 [2,3]
// 差集
let differenceAB = a.filter(x => !b.includes(x));
// 打印 [1]
JS求出两个数组的交集和差集
最新推荐文章于 2022-01-14 14:18:11 发布
let a = [1, 2, 3];
let b = [3, 5, 2];
// 交集
let intersection = a.filter(x => b.includes(x));
// 打印 [2,3]
// 差集
let differenceAB = a.filter(x => !b.includes(x));
// 打印 [1]