unique-concat
Concatenates two arrays, removing duplicates in the process and returns one array with unique values.
Last updated 13 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install unique-concat 
SYNC missed versions from official npm registry.

unique-concat build status

testling badge

Concatenates two arrays, removing duplicates in the process and returns one array with unique values.

var concat = require('unique-concat');
var res = concat([ 1, 2, 3 ], [ 1, 2, 3, 4, 5, 6])
console.log(res);
// => [1, 2, 3, 4, 5, 6]

Installation

npm install unique-concat

API

###function uniqueConcat(arr1, arr2[, identity])

/**
 * Concatenates two arrays, removing duplicates in the process and returns one array with unique values.
 * In case the elements in the array don't have a proper built in way to determine their identity,
 * a custom identity function must be provided.
 *
 * As an example, {Object}s all return '[ 'object' ]' when .toString()ed and therefore require a custom
 * identity function.
 *
 * @name exports
 * @function unique-concat
 * @param arr1 {Array} first batch of elements
 * @param arr2 {Array} second batch of elements
 * @param identity {Function} (optional) supply an alternative way to get an element's identity
 */

Identity function example

var identity = function (obj) { return obj.a; }
var res = concat([{ a: 1 }, { a: 2, b: 1}], [{ a: 2, b: 2 }, { a: 3 }], identity);
console.log(res);
// => [ { a: 1 }, { a: 2, b: 2 }, { a: 3 } ]

For more examples see tests

License

MIT

Current Tags

  • 0.2.2                                ...           latest (13 years ago)

7 Versions

  • 0.2.2                                ...           13 years ago
  • 0.2.1                                ...           13 years ago
  • 0.2.0                                ...           13 years ago
  • 0.1.3                                ...           13 years ago
  • 0.1.2                                ...           13 years ago
  • 0.1.1                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
Maintainers (1)
Downloads
Total 16
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (4)

© 2010 - cnpmjs.org x YWFE | Home | YWFE