-
Notifications
You must be signed in to change notification settings - Fork 0
zip
Subhajit Sahu edited this page Jun 18, 2020
·
8 revisions
Combines matching entries from all lists. 🏃 📼 📦 🌔 📒
Similar: cartesianProduct, zip.
lists.zip(xs, [fm], [ft], [vd]);
// xs: n lists
// fm: map function (vs, k)
// ft: till function (dones) (some)
// vd: default value
const lists = require('extra-lists');
const array = require('extra-array');
var x = [['a', 'b', 'c'], [1, 2, 3]];
var y = [['a', 'b'], [10, 20]];
lists.zip([x, y]).map(c => [...c]);
// [ [ 'a', 'b' ], [ [ 1, 10 ], [ 2, 20 ] ] ] (shortest)
lists.zip([x, y], ([a, b]) => a + b).map(c => [...c]);
// [ [ 'a', 'b' ], [ 11, 22 ] ]
lists.zip([x, y], null, array.some).map(c => [...c]);
// [ [ 'a', 'b' ], [ [ 1, 10 ], [ 2, 20 ] ] ] (shortest)
lists.zip([x, y], null, array.every, 0).map(c => [...c]);
// [ [ 'a', 'b', 'c' ], [ [ 1, 10 ], [ 2, 20 ], [ 3, 0 ] ] ] (longest)