Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A small utility that attaches an `add` method to a regular Array instance which silently ignores duplicate values.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

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" ]
Something went wrong with that request. Please try again.