-
Notifications
You must be signed in to change notification settings - Fork 0
partitionAs
Subhajit Sahu edited this page Dec 28, 2022
·
15 revisions
Segregate entries by similarity.
Alternatives: partition, partitionAs.
function partitionAs(x, fm)
// x: entries
// fm: map function (v, k, x)
const xilists = require('extra-ilists');
var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 4]];
xilists.partitionAs(x, v => v % 2 == 0);
// → Map(2) {
// → false => [ [ 'a', 'c' ], [ 1, 3 ] ],
// → true => [ [ 'b', 'd' ], [ 2, 4 ] ]
// → }
var x = [['a', 'b', 'c', 'd', 'e'], [1, 2, 3, 4, 5]];
xilists.partitionAs(x, v => v % 3);
// → Map(3) {
// → 1 => [ [ 'a', 'd' ], [ 1, 4 ] ],
// → 2 => [ [ 'b', 'e' ], [ 2, 5 ] ],
// → 0 => [ [ 'c' ], [ 3 ] ]
// → }