Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

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…

install

npm i array.combine

Downloadsweekly downloads

3

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability