数组去重:
let arr = [3, 5, 2, 2, 5, 5];
let unique = [...new Set(arr)];
并、交、差集
let a = new Set([1, 2, 3]);
let b = new Set([4, 3, 2]);
- 并集:let unique = new Set([...a, ...b]);
- 交集:let intersect = new Set([...a]).filter(x => b.has(x));
- 差集:let diffrence = new Set([...a]).filter(x => !b.has(x)); // 这里是一种左差a-b,还有一种右差b-a,自行修改即可