npm

Check out our latest tech talk, "JavaScript Supply Chain Security," presented by VP of Security, Adam Baldwin.Watch it here »

arr-uniq

1.0.0 • Public • Published

Array uniq

Build Status

Generic array uniq function which supports equals predicate function.

Install

npm install arr-uniq

Usage

var uniq = require('arr-uniq');
 
uniq([1, 1, 2, 2, 3, 3, 3, 4]);
//=> [1, 2, 3, 4]
 
uniq([{id: 1}, {id: 2}, {id: 2}, {id: 3}], function equals(a, b) {
    return a.id === b.id;
});
//=> [{id: 1}, {id: 2}, {id: 3}]

API

uniq(array, [equalsPredicate])

Creates a duplicate-free version of an array, using equalsPredicate to compare if items are equal.

array

Required
Type: array

Input array.

equalsPredicate

Type: function
Default: function(a, b) { return a === b; }

Equality function. Should return true if a and b items are equal.

License

MIT

install

npm i arr-uniq

Downloadsweekly downloads

11

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability