now-flow
Version:
Add deployment workflows to Zeit now
22 lines (18 loc) • 713 B
JavaScript
/**
* A fast impementation of an algorithm that takes an array and returns a copy of the array without duplicates.
* We used to use `array-unique` ( https://github.com/jonschlinkert/array-unique/blob/5d1fbe560da8125e28e4ad6fbfa9daaf9f2ec120/index.js )
* but from running benchmarks, found the implementation to be too slow. This implementation has show to be upto ~10x faster for large
* projects
* @param {Array} arr Input array that potentially has duplicates
* @returns {Array} An array of the unique values in `arr`
*/
module.exports = arr => {
const len = arr.length
const res = []
const o = {}
let i
for (i = 0; i < len; i += 1) {
o[arr[i]] = o[arr[i]] || res.push(arr[i])
}
return res
}