-
Notifications
You must be signed in to change notification settings - Fork 0
partitionAs
Subhajit Sahu edited this page Feb 4, 2021
·
15 revisions
Segregates values by similarity. 🏃 📼 📦 🌔 📒
Alternatives: partition, partitionAs.
lists.partitionAs(x, [fm]);
// x: lists
// fm: map function (v, k, x)
// --> Map {key => values}
const lists = require('extra-lists');
var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 4]];
lists.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]];
lists.partitionAs(x, v => v % 3);
// Map(3) {
// 1 => [ [ 'a', 'd' ], [ 1, 4 ] ],
// 2 => [ [ 'b', 'e' ], [ 2, 5 ] ],
// 0 => [ [ 'c' ], [ 3 ] ]
// }