countEach (original) (raw)
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 }