采用es6方法

// 100000数据耗时57  
function distinct(a, b) {
    return Array.from(new Set([...a, ...b]))
}
  

第二种方法:利用对象的属性不会重复,校验数组是否重复

// 150万数据,耗时93

function distinct(a, b) {
  let arr = a.concat(b)
  let result = []
  let obj = {}

  for (let i of arr) {
    if (!obj[i]) {
      result.push(i)
      obj[i] = 1
    }
  }

  return result
}

相关文章:

  • 2022-02-28
  • 2022-12-23
  • 2021-09-11
  • 2022-01-16
  • 2021-08-02
  • 2021-08-12
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
相关资源
相似解决方案