Skip to content
Subhajit Sahu edited this page Feb 4, 2021 · 10 revisions

Combines matching entries from all entries. 🏃 📼 📦 🌔 📒

Similar: cartesianProduct, zip.

entries.zip(xs, [fm], [ft], [vd]);
// xs: n entries
// fm: map function (vs, k)
// ft: till function (dones) (some)
// vd: default value
const entries = require("extra-entries");
const array = require("extra-array");

var x = [["a", 1], ["b", 2], ["c", 3]];
var y = [["a", 10], ["b", 20]];
[...entries.zip([x, y])];
// [ [ "a", [ 1, 10 ] ], [ "b", [ 2, 20 ] ] ] (shortest)

[...entries.zip([x, y], ([a, b]) => a + b)];
// [ [ "a", 11 ], [ "b", 22 ] ]

[...entries.zip([x, y], null, array.some)];
// [ [ "a", [ 1, 10 ] ], [ "b", [ 2, 20 ] ] ] (shortest)

[...entries.zip([x, y], null, array.every, 0)];
// [ [ "a", [ 1, 10 ] ], [ "b", [ 2, 20 ] ], [ "c", [ 3, 0 ] ] ] (longest)

references

Clone this wiki locally