js用Set 实现并集(Union)、交集(Intersect)和差集(Difference)
直接上代码:
let a new Set([1, 2, 3]);
let b new Set([4, 3, 2]);// 并集
let union new Set([...a, ...b]);
// Set {1, 2, 3, 4}// 交集
let intersect new Set([...a].filter(x > b.has(x)));//ES6
var intersect new Set([...a].filter(function(x){…
2026/7/16 7:57:36