1.0.1 • Published 6 years ago

wwa-array-unique v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

nodejs-array-unique

Build Status

Another implementation of jonschlinkert/array-unique, which is faster on larger arrays

Install

Install with npm:

npm install --save wwa-array-unique

Usage

const unique = require('wwa-array-unique');

let arr = ['a', 'b', 'c', 'c'];
console.log(unique(arr)) //=> ['a', 'b', 'c']
console.log(arr)         //=> ['a', 'b', 'c']

/* The above modifies the input array. To prevent that: */
const unique = require("array-unique").immutable;

let arr = ['a', 'b', 'c', 'c'];
console.log(unique(arr)) //=> ['a', 'b', 'c']
console.log(arr)         //=> ['a', 'b', 'c', 'c']

Benchmarks

Table values are number of operations per second. Unlike the original version, my implementation of immutable is faster than unique.

NodeJS 6

array-unique (mutable)wwa-array-unique (mutable)array-unique (immutable)wwa-array-unique (immutable)
102,764,501315,9912,239,5661,119,888
20888,532202,232726,592590,641
10065,66268,41553,382208,231
1,00067,71671,17453,714202,922
10,0003,02526,3262,51948,769

NodeJS 8

array-unique (mutable)wwa-array-unique (mutable)array-unique (immutable)wwa-array-unique (immutable)
102,013,1621,569,8841,616,8992,259,815
201,026,325887,556774,4101,168,428
10080,493177,24758,954198,410
1,00076,875165,29558,541192,993
10,0003,76036,6232,86646,911

NodeJS 11

array-unique (mutable)wwa-array-unique (mutable)array-unique (immutable)wwa-array-unique (immutable)
107,346,0261,902,6765,013,3644,984,386
201,230,241996,9851,132,9961,595,666
10060,376189,20659,443222,805
1,00056,450208,54656,999240,402
10,0002,83038,4462,72649,699