JavaScript 中 计算数组的 差集、交集、并集、补集
糊涂粥 于 2023-06-14 11:30:04

直接上代码

//交集
let intersect = a.filter(v => b.includes(v));
//差集
let minus = a.filter(v => !b.includes(v));
//补集
let complement = a.filter(v => !b.includes(v)).concat(b.filter(v => !a.includes(v)))
//并集
let unionSet = a.concat(b.filter(v => !a.includes(v)));


阅读 (5307)