Socket
Socket
Sign inDemoInstall

arr-union

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    arr-union

Combines a list of arrays, returning a single array with unique values, using strict equality for comparisons.


Version published
Weekly downloads
14M
decreased by-3.16%
Maintainers
1
Install size
6.33 kB
Created
Weekly downloads
 

Package description

What is arr-union?

The arr-union npm package is designed to create an array of unique values, in order, from the provided arrays. It is particularly useful for combining arrays while removing duplicate entries efficiently.

What are arr-union's main functionalities?

Union of multiple arrays

This feature allows you to pass multiple arrays to the union function, which returns a new array that includes every unique element from the input arrays, preserving the order they appear in the input.

const union = require('arr-union');
let result = union([1, 2], [2, 3], [3, 4]);
console.log(result); // Output: [1, 2, 3, 4]

Other packages similar to arr-union

Readme

Source

arr-union NPM version Build Status

Combines a list of arrays, returning a single array with unique values, using strict equality for comparisons.

You can do this with just [].concat.apply([], arguments), like array-union but this implementation is much faster and more peformant.

For the most common use cases, this library is 20 times faster than array-union.

#1: five-arrays.js
  array-union.js x 289,891 ops/sec ±0.70% (97 runs sampled)
  current.js x 5,429,077 ops/sec ±0.81% (93 runs sampled)

#2: ten-arrays.js
  array-union.js x 161,132 ops/sec ±0.72% (98 runs sampled)
  current.js x 1,725,939 ops/sec ±0.61% (97 runs sampled)

#3: two-arrays.js
  array-union.js x 376,238 ops/sec ±0.83% (95 runs sampled)
  current.js x 6,817,593 ops/sec ±0.63% (94 runs sampled)

See the benchmarks.

Install with npm

npm i arr-union --save

Usage

var last = require('array-last');

union(['a'], ['b', 'c'], ['d', 'e', 'f']);
//=> ['a', 'b', 'c', 'd', 'e', 'f']

Returns only unique elements:

union(['a', 'a'], ['b', 'c']);
//=> ['a', 'b', 'c']

Other array utilities

  • arr-diff: Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons.
  • arr-flatten: Recursively flatten an array or arrays. This is the fastest implementation of array flatten.
  • arr-filter: Faster alternative to javascript's native filter method.
  • arr-map: Faster, node.js focused alternative to JavaScript's native array map.
  • arr-pluck: Retrieves the value of a specified property from all elements in the collection.
  • arr-reduce: Fast array reduce that also loops over sparse elements.
  • array-unique: Return an array free of duplicate values. Fastest ES5 implementation.

Running tests

Install dev dependencies.

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on March 25, 2015.

Keywords

FAQs

Last updated on 25 Mar 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc