Skip to content
Subhajit Sahu edited this page May 19, 2020 · 26 revisions

Combines values from arrays. 🏃 📼 📦 🌔

Similar: [cartesianProduct], [zip].

array.zip(xs, [fn], [ths]);
// xs:  arrays
// fn:  map function (vs, i, xs)
// ths: this argument
const array = require('extra-array');

var x = [1, 2, 3];
var y = [4, 5];
array.zip([x, y]);
// [ [ 1, 4 ], [ 2, 5 ] ] (shortest)

array.zip([x, y], ([a, b]) => a + b);
// [ 5, 7 ]

array.zip([x, y], null, array.some);
// [ [ 1, 4 ], [ 2, 5 ] ] (shortest)

array.zip([x, y], null, array.every, 0);
// [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (longest)

array.zip([x, y], null, array.head, 0);
// [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (first)

references

Clone this wiki locally