bluejeansandrain.unique

Utility that creates an Array instance with modified push, unshift, and splice methods that check for uniqueness before inserting values.

npm install bluejeansandrain.unique
4 downloads in the last month

node-unique

Utility that creates an Array instance with modified push, unshift, and splice methods that check for uniqueness before inserting values. This utility is pretty dumb in that it just iterates over the array looking for a value that matches using the === operator. It's not going to be fast over large arrays.

Example:

var Unique = require( 'bluejeansandrain.unique' );

var arr = new Unique();
arr.push( 'a', 'b', 'c' );
arr.push( 'a' );

console.log( arr );

Output:

> ["a", "b", "c" ]

Unique is not actually a class though you can use new with it. It's just a factory method that creates a regular array and then bolts a method on the side. So new is totally optional.

Example:

var arr = unique();

Unique can also be used to deduplicate existing arrays.

Example:

var dup = ['a', 'b', 'c', 'a'];
var arr = unique( dup );
console.log( arr );

Output:

> ["a", "b", "c" ]
npm loves you