-
Notifications
You must be signed in to change notification settings - Fork 1
partition
Subhajit Sahu edited this page Dec 2, 2022
·
17 revisions
Segregate values by test result.
Alternatives: partition, partitionAs.
function partition(x, ft)
// x: a set
// ft: test function (v, v, x)
const set = require('extra-set');
var x = new Set([1, 2, 3, 4]);
set.partition(x, v => v % 2 == 0);
// → [ Set(2) { 2, 4 }, Set(2) { 1, 3 } ]
var x = new Set([1, 2, 3, 4, 5]);
set.partition(x, v => v % 2 == 1);
// → [ Set(3) { 1, 3, 5 }, Set(2) { 2, 4 } ]