Skip to content

countAs

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

Counts occurrences of values. 🏃 📼 📦 🌔 📒

Alternatives: count, countAs.
Similar: count, partition.

iterable.countAs(x, [fm]);
// x:  an iterable
// fm: map function (v, i, x)
// --> Map {value => count}
const iterable = require('extra-iterable');

var x = [1, 1, 2, 2, 4];
iterable.countAs(x);
// Map(3) { 1 => 2, 2 => 2, 4 => 1 }

var x = [1, 2, 3, 4];
iterable.countAs(x, v => v % 2);
// Map(2) { 1 => 2, 0 => 2 }

references

Clone this wiki locally