1.0.0 • Published 8 years ago
array.combine v1.0.0
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.combineconst { 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…
1.0.0
8 years ago