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
13M
decreased by-0.65%
Maintainers
1
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.

This library is 15-20 times faster and more performant (scales better) than array-union, which just uses [].concat.apply([], arguments).

Benchmarks

See the benchmarks.

#1: five-arrays.js
  array-union.js x 245,487 ops/sec ±0.99% (96 runs sampled)
  current.js x 5,267,661 ops/sec ±0.63% (98 runs sampled)

#2: ten-arrays.js
  array-union.js x 134,784 ops/sec ±0.51% (94 runs sampled)
  current.js x 1,919,143 ops/sec ±0.45% (100 runs sampled)

#3: two-arrays.js
  array-union.js x 308,374 ops/sec ±0.75% (96 runs sampled)
  current.js x 7,361,915 ops/sec ±0.67% (95 runs sampled)

Install

Install with npm

$ npm i arr-union --save

Usage

var union = require('arr-union');

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… more
  • 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 © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on June 15, 2015.

Keywords

FAQs

Last updated on 15 Jun 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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc