-
Notifications
You must be signed in to change notification settings - Fork 1
partitionAs
Subhajit Sahu edited this page Jun 12, 2020
·
14 revisions
Segregates map keeping similar values together. 🏃 📼 📦 🌔
map.partitionOn(x, [fn], [ths]);
// x: an array
// fn: map function (v, k, x)
// ths: this argument
// --> Map {key => values}
const map = require('extra-map');
var x = new Map([['A', 1], ['B', 2], ['C', 3]]);
map.partitionOn(x);
// Map(3) { 1 => [ 1 ], 2 => [ 2 ], 3 => [ 3 ] }
map.partitionOn(x, v => v % 2);
// Map(2) { 1 => [ 1, 3 ], 0 => [ 2 ] }