-
Notifications
You must be signed in to change notification settings - Fork 1
cartesianProduct
Subhajit Sahu edited this page Dec 2, 2022
·
15 revisions
List cartesian product of sets.
function cartesianProduct(xs, fm)
// xs: sets
// fm: map function (vs, vs)
const set = require('extra-set');
var x = new Set([1, 2, 3]);
var y = new Set([10, 20]);
[...set.cartesianProduct([x, y])];
// → [
// → Set(2) { 1, 10 },
// → Set(2) { 1, 20 },
// → Set(2) { 2, 10 },
// → Set(2) { 2, 20 },
// → Set(2) { 3, 10 },
// → Set(2) { 3, 20 }
// → ]
[...set.cartesianProduct([x, y], a => set.max(a)[1])];
// → [ 10, 20, 10, 20, 10, 20 ]