@extra-array/count-on.min
v2.6.72
Published
Counts occurrences of values.
Downloads
173
Readme
Counts occurrences of values. :running: :vhs: :package: :moon:
Alternatives: one, all. This is part of package extra-array.
This is browserified, minified version of @extra-array/count-on. It is exported as global variable array_countOn. CDN: unpkg, jsDelivr.
array.countOn(x, [fn], [ths]);
// x: an array
// fn: map function (v, i, x)
// ths: this argument
// --> Map {value => count}
const array = require('extra-array');
var x = [1, 1, 2, 2, 4];
array.countOn(x);
// Map(3) { 1 => 2, 2 => 2, 4 => 1 }
var x = [1, 2, 3, 4];
array.countOn(x, v => v % 2);
// Map(2) { 1 => 2, 0 => 2 }