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