Removes duplicate values.
npm install @extra-array/uniqueRemoves duplicate values.
:package:
:smiley_cat:
:running:
:vhs:
:moon:
:scroll:
:newspaper:
:blue_book:
> Alternatives: [unique], [isUnique].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
``javascript`
array.unique(x, [fc], [fm]);
// x: an array
// fc: compare function (a, b)
// fm: map function (v, i, x)
> :stopwatch: Compare function => O(n²).
`javascript
const array = require("extra-array");
var x = [1, 2, 3, 4, 2, 3];
array.unique(x);
// [ 1, 2, 3, 4 ]
var x = [1, 2, 3, 4, -2, -3];
array.unique(x, (a, b) => Math.abs(a) - Math.abs(b));
// [ 1, 2, 3, 4 ]
array.unique(x, null, v => Math.abs(v));
// [ 1, 2, 3, 4 ]
``
- Data.List.nub: Haskell
- List-Extra.unique: elm
- List-Extra.uniqueBy: elm
- _.uniq: lodash
- _.uniqBy: lodash
- _.uniqWith: lodash
- Array.unique: sugarjs
[unique]: https://github.com/nodef/extra-array/wiki/unique
[isUnique]: https://github.com/nodef/extra-array/wiki/isUnique