-
Notifications
You must be signed in to change notification settings - Fork 5
countEach
Subhajit Sahu edited this page May 3, 2023
·
1 revision
Count occurrences of each distinct value.
function countEach(x, fm)
// x: an array
// fm: map function (v, i, x)
const xarray = require('extra-array');
var x = [1, 1, 2, 2, 4];
xarray.countEach(x);
// → Map(3) { 1 => 2, 2 => 2, 4 => 1 }
var x = [1, 2, 3, 4];
xarray.countEach(x, v => v % 2);
// → Map(2) { 1 => 2, 0 => 2 }