• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..16-Feb-2021-

test/H03-May-2022-

.npmignoreH A D16-Feb-202198 1513

LICENSEH A D16-Feb-20211.1 KiB2317

README.mdH A D16-Feb-20211.2 KiB4731

package.jsonH A D16-Feb-2021678 3736

README.md

1uniq
2====
3Removes all duplicates from an array in place.
4
5Usage
6=====
7First install using npm:
8
9    npm install uniq
10
11Then use it as follows:
12
13```javascript
14
15var arr = [1, 1, 2, 2, 3, 5]
16
17require("uniq")(arr)
18console.log(arr)
19
20//Prints:
21//
22//  1,2,3,5
23//
24```
25
26## `require("uniq")(array[, compare, sorted])`
27Removes all duplicates from a sorted array in place.
28
29* `array` is the array to remove items from
30* `compare` is an optional comparison function that returns 0 when two items are equal, and something non-zero when they are different.  If unspecified, then the default equals will be used.
31* `sorted` if true, then assume array is already sorted
32
33**Returns:** A reference to `array`
34
35**Time Complexity:** `O(array.length * log(arra.length))` or `O(array.length)` if `sorted`
36
37
38## Why use this instead of underscore.uniq[ue]?
39A few reasons:
40
41* This library updates the array in place without making an extra copy (and so it is faster for large arrays)
42* It also accepts a custom comparison function so you can remove duplicates from arrays containing object
43* It is more modular in the sense that it doesn't come with a bazillion other utility grab bag functions.
44
45# Credits
46(c) 2013 Mikola Lysenko. MIT License
47