UNPKG

@extra-array/count-as

Version:
52 lines (38 loc) 1.49 kB
Counts occurrences of values. [:package:](https://www.npmjs.com/package/@extra-array/count-as) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/count-as) [:vhs:](https://asciinema.org/a/332034) [:moon:](https://www.npmjs.com/package/@extra-array/count-as.min) [:scroll:](https://unpkg.com/@extra-array/count-as/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [count], [countAs].<br> > Similar: [count], [partition]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.countAs(x, [fm]); // x: an array // fm: map function (v, i, x) // → Map {value => count} ``` ```javascript const array = require("extra-array"); var x = [1, 1, 2, 2, 4]; array.countAs(x); // Map(3) { 1 => 2, 2 => 2, 4 => 1 } var x = [1, 2, 3, 4]; array.countAs(x, v => v % 2); // Map(2) { 1 => 2, 0 => 2 } ``` <br> <br> ## References - [List-Extra.count: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#count) - [_.countBy: lodash](https://lodash.com/docs/4.17.15#countBy) - [count-iterable-values: @zeke](https://www.npmjs.com/package/count-iterable-values) [count]: https://github.com/nodef/extra-array/wiki/count [countAs]: https://github.com/nodef/extra-array/wiki/countAs [partition]: https://github.com/nodef/extra-array/wiki/partition