Skip to content

countAs

Subhajit Sahu edited this page Jun 17, 2020 · 14 revisions

Counts occurrences of values. 🏃 📼 📦 🌔 📒

Alternatives: count, countAs.

entries.countAs(x, fn);
// x:  entries
// fn: map function (v, k, x)
// --> Map {value => count}
const entries = require('extra-entries');

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 }

references

Clone this wiki locally