-
Notifications
You must be signed in to change notification settings - Fork 5
zip
Subhajit Sahu edited this page Mar 13, 2020
·
26 revisions
Combines values from n arrays, with a function.
array.zip(x, fn);
// xs: n arrays
// fn: combine function (a, b, c, ...)
// ths: this argument
// --> combined values
const array = require('extra-array');
array.zip([[1, 2, 3], [4, 5, 6]]);
// [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
array.zip([[1, 2, 3], [4, 5, 6], [0, 0, 0]]);
// [ [ 1, 4, 0 ], [ 2, 5, 0 ], [ 3, 6, 0 ] ]
array.zip([[1, 2, 3], [4, 5, 6]], (a, b) => a + b);
// [ 5, 7, 9 ]