main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
709 bytes
|
Line | |
---|
1 | import _reduce from "./internal/_reduce.js";
|
---|
2 | import curry from "./curry.js";
|
---|
3 | /**
|
---|
4 | * Returns the number of items in a given `list` matching the predicate `f`
|
---|
5 | *
|
---|
6 | * @func
|
---|
7 | * @memberOf R
|
---|
8 | * @since v0.28.0
|
---|
9 | * @category List
|
---|
10 | * @sig (a -> Boolean) -> [a] -> Number
|
---|
11 | * @param {Function} predicate to match items against
|
---|
12 | * @return {Array} list of items to count in
|
---|
13 | * @example
|
---|
14 | *
|
---|
15 | * const even = x => x % 2 == 0;
|
---|
16 | *
|
---|
17 | * R.count(even, [1, 2, 3, 4, 5]); // => 2
|
---|
18 | * R.map(R.count(even), [[1, 1, 1], [2, 3, 4, 5], [6]]); // => [0, 2, 1]
|
---|
19 | */
|
---|
20 |
|
---|
21 | var count =
|
---|
22 | /*#__PURE__*/
|
---|
23 | curry(function (pred, list) {
|
---|
24 | return _reduce(function (a, e) {
|
---|
25 | return pred(e) ? a + 1 : a;
|
---|
26 | }, 0, list);
|
---|
27 | });
|
---|
28 | export default count; |
---|
Note:
See
TracBrowser
for help on using the repository browser.