Sort unique is a package that sorts an array and removes all duplicate elements (without modifying the original array).
You can download and install this package from NPM with npm i -S sort-unique
.
Sorts an array and removes all duplicates.
array
: the array to processcompare
: a function that compares two items in the array, returning1
for greater than,0
for equal, and-1
for less than.
If compare
is unspecified, it will default to
(a, b) => {
if (a > b) {
return 1;
} else if (a < b) {
return -1;
} else {
return 0;
}
};