-
Notifications
You must be signed in to change notification settings - Fork 3
cartesianProduct
Subhajit Sahu edited this page Jun 11, 2020
·
13 revisions
Lists cartesian product of objects. 🏃 [:vhs:] 📦 🌔 📒
Similar: cartesianProduct, zip.
object.cartesianProduct(xs, [fn]);
// xs: objects
// fn: map function (v, null, null)const object = require('extra-object');
var x = {a: 1, b: 2, c: 3};
var y = {d: 10, e: 20};
[...object.cartesianProduct([x, y])];
// [
// { a: 1, d: 10 },
// { a: 1, e: 20 },
// { b: 2, d: 10 },
// { b: 2, e: 20 },
// { c: 3, d: 10 },
// { c: 3, e: 20 }
// ]
[...object.cartesianProduct([x, y], a => object.max(a))];
// [
// [ 'd', 10 ],
// [ 'e', 20 ],
// [ 'd', 10 ],
// [ 'e', 20 ],
// [ 'd', 10 ],
// [ 'e', 20 ]
// ]