array 标签

多种数组去重性能对比 有更新!

测试模板

// 创建一个 1 ~ 10w 的数组,Array.from为ES6语法
let arr1 = Array.from(new Array(1000000), (x, index) => { 
  return index
})

let arr2 = Array.from(new Array(500000), (x, index) => {
  return index + index
})

let start = new Date().getTime()
console.log('开始数组去重')

// 数组去重
function distinct(a, b) {
  let arr = a.concat(b);
  // 去重方法
}



console.log('去重后的长度', distinct(arr1, arr2).length)
let end = new Date().getTime()
console.log('耗时', end - start + 'ms')
阅读全文 »