@extra-array/unique
Version:
Removes duplicate values.
58 lines (43 loc) • 1.82 kB
Markdown
Removes duplicate values.
[:package:](https://www.npmjs.com/package/@extra-array/unique)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/unique)
[:vhs:](https://asciinema.org/a/332149)
[:moon:](https://www.npmjs.com/package/@extra-array/unique.min)
[:scroll:](https://unpkg.com/@extra-array/unique/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [unique], [isUnique].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```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 ]
```
<br>
<br>
## References
- [Data.List.nub: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:nub)
- [List-Extra.unique: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#unique)
- [List-Extra.uniqueBy: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#uniqueBy)
- [_.uniq: lodash](https://lodash.com/docs/4.17.15#uniq)
- [_.uniqBy: lodash](https://lodash.com/docs/4.17.15#uniqBy)
- [_.uniqWith: lodash](https://lodash.com/docs/4.17.15#uniqWith)
- [Array.unique: sugarjs](https://sugarjs.com/docs/#/Array/unique)
[unique]: https://github.com/nodef/extra-array/wiki/unique
[isUnique]: https://github.com/nodef/extra-array/wiki/isUnique