es6去重
set结构数组去重:
const arr = ['a','bb','22','a','haha','haha','22'];
let unique = new Set(arr);
console.log(Array.from(unique));
// 数组去重
let arr = [1, 1, 2, 3];
let unique = [... new Set(arr)];
let a = new Set([1, 2, 3]);
let b = new Set([4, 3, 2]);
// 并集
let union = [...new Set([...a, ...b])]; // [1,2,3,4]
// 交集
let intersect = [...new Set([...a].filter(x => b.has(x)))]; [2,3]
// 差集
let difference = Array.from(new Set([...a].filter(x => !b.has(x)))); [1]