-
Notifications
You must be signed in to change notification settings - Fork 5
zip
Subhajit Sahu edited this page May 3, 2023
·
26 revisions
Combine values from arrays.
Similar: cartesianProduct, zip.
function zip(xs, fm, fe, vd?)
// xs: arrays
// fm: map function (vs, i)
// fe: end function (dones) [some]
// vd: default value
const xarray = require('extra-array');
var x = [1, 2, 3];
var y = [4, 5];
xarray.zip([x, y]);
// → [ [ 1, 4 ], [ 2, 5 ] ] (shortest)
xarray.zip([x, y], ([a, b]) => a + b);
// → [ 5, 7 ]
xarray.zip([x, y], null, xarray.some);
// → [ [ 1, 4 ], [ 2, 5 ] ] (shortest)
xarray.zip([x, y], null, xarray.every, 0);
// → [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (longest)
xarray.zip([x, y], null, xarray.head, 0);
// → [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (first)