array.combine
v1.0.0
Published
JavaScript utility to combine arrays.
Downloads
207
Readme
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…