1、数组去重

let arr = [3, 5, 2, 2, 5, 5];
let unique = [...new Set(arr)];
// [3, 5, 2]

2、并集(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)));
// set {2, 3}

// 差集
let difference = new Set([...a].filter(x => !b.has(x)));
// Set {1}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-07-05
  • 2021-11-04
  • 2021-04-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2022-01-04
  • 2021-08-03
  • 2021-06-06
  • 2022-12-23
相关资源
相似解决方案