@extra-iterable/unique

Removes duplicate values. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Usage no npm install needed!

<script type="module">
  import extraIterableUnique from 'https://cdn.skypack.dev/@extra-iterable/unique';
</script>

README

Removes duplicate values. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Alterantives: unique, isUnique.

This is part of package extra-iterable.


iterable.unique(x, [fc], [fm]);
// x:  an iterable
// fc: compare function (a, b)
// fm: map function (v, i, x)

:stopwatch: Compare function => O(n²).

const iterable = require("extra-iterable");

var x = [1, 2, 3, 4, 2, 3];
[...iterable.unique(x)];
// [ 1, 2, 3, 4 ]

var x = [1, 2, 3, 4, -2, -3];
[...iterable.unique(x)];
// [ 1, 2, 3, 4, -2, -3 ]

[...iterable.unique(x, (a, b) => Math.abs(a) - Math.abs(b))];
// [ 1, 2, 3, 4 ]

[...iterable.unique(x, null, v => Math.abs(v))];
// [ 1, 2, 3, 4 ]


References