Skip to content

partition

Subhajit Sahu edited this page Feb 3, 2021 · 17 revisions

Segregates values by test result. 🏃 📼 📦 🌔 📒

Alternatives: partition, partitionAs.


set.partition(x, ft);
// x:  a set
// ft: test function (v, v, x)
// --> [satisfies, doesnt]
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 } ]


References

Clone this wiki locally