nub
Uniqueness functions
Last updated 12 years ago by substack .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nub 
SYNC missed versions from official npm registry.

nub

Return all the unique elements of an array. You can specify your own uniqueness comparison function with nub.by too.

These work like haskell's nub and nubBy functions in Data.List.

example

$ node
> var nub = require('nub')
> nub([1,2,2,3,1,3])
[ 1, 2, 3 ]
> nub.by([ 2, 3, 5, 7, 8 ], function (x,y) { return x + y === 10 })
[ 2, 3, 5 ]

methods

var nub = require('nub')

nub(xs)

Return a new array with all the uniqe elements in xs.

Uniqueness is calculated === style so the types matter.

nub.by(xs, cmp)

Use cmp(x,y) function to compare elements instead of the default. cmp should return whether the two elements are equal as a boolean.

install

With npm do:

npm install nub

To use nub in the browser, use browserify or fetch a UMD build from browserify CDN.

license

MIT

Current Tags

  • 1.0.0                                ...           latest (12 years ago)

2 Versions

  • 1.0.0                                ...           12 years ago
  • 0.0.0                                ...           15 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |