@extra-array/count
Version:
Counts values which satisfy a test.
51 lines (37 loc) • 1.46 kB
Markdown
Counts values which satisfy a test.
[:package:](https://www.npmjs.com/package/@extra-array/count)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/count)
[:vhs:](https://asciinema.org/a/332033)
[:moon:](https://www.npmjs.com/package/@extra-array/count.min)
[:scroll:](https://unpkg.com/@extra-array/count/)
[: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.count(x, ft);
// x: an array
// ft: test function (v, i, x)
```
```javascript
const array = require("extra-array");
var x = [1, 1, 2, 2, 4];
array.count(x, v => v % 2 === 1);
// 2
array.count(x, v => v % 2 === 0);
// 3
```
<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)
- [Array.count: sugarjs](https://sugarjs.com/docs/#/Array/count)
- [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