array.combine

1.0.0 • Public • Published

array.combine

A JavaScript utility to combine arrays.

npm version Build Status Coverage Status dependencies Status Known Vulnerabilities


Use this if you want to combine multiple arrays to create a new array where each element from each array is combined with each element in each other array.

Quick start

npm install --save array.combine
const { combine } = require('array.combine');
combine([1, 2], [3, 4]); // => [1, 3], [1, 4], [2, 3], [2, 4]

Combine

const { combine, combineWith } = require('array.combine');

API

combine(arr1:Array<*>, [arrN:Array<*>]) :Array<*>

combine([1, 2], [3, 4]); // => [1, 3], [1, 4], [2, 3], [2, 4]

combineWith(arr1:Array<*>, [...arrN:Array<*>], iteratee:function) :Array<*>

const add = (n1, n2) => n1 + n2;
combineWith([1, 2], [3, 4], add); // => [4, 5, 5, 6]

add is invoked with (item1:*, [itemN:*]).

In this example it would be (1, 3), (1, 4), etc…

Combine/FP

const { combine, combineWith } = require('array.combine/fp');

API

combine(arrays:Array<Array<*>>) :Array<*>

combine([[1, 2], [3, 4]]); // => [1, 3], [1, 4], [2, 3], [2, 4]

combineWith(iteratee:function, arrays:Array<Array<*>) :Array<*>

const add = (n1, n2) => n1 + n2;
const addAll = (numbers) => numbers.reduce(add, 0);
combineWith(addAll, [[1, 2], [3, 4]]); // => [4, 5, 5, 6]

addAll is invoked with (Array<*>).

In this example it would be ([1, 3]), ([1, 4]), etc…

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    42
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    42

Package Sidebar

Install

npm i array.combine

Weekly Downloads

42

Version

1.0.0

License

MIT

Unpacked Size

11.7 kB

Total Files

14

Last publish

Collaborators

  • moeriki