-
Notifications
You must be signed in to change notification settings - Fork 1
countAs
Subhajit Sahu edited this page Dec 5, 2022
·
14 revisions
Count occurrences of values.
function countAs(x, fm)
// x: a map
// fm: map function (v, k, x)
const map = require('extra-map');
var x = new Map([['a', 1], ['b', 1], ['c', 2], ['d', 2], ['e', 4]]);
map.countAs(x);
// → Map(3) { 1 => 2, 2 => 2, 4 => 1 }
var x = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4]]);
map.countAs(x, v => v % 2);
// → Map(2) { 1 => 2, 0 => 2 }