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:
747 bytes
|
Line | |
---|
1 | var _reduce =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_reduce.js");
|
---|
4 |
|
---|
5 | var curry =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./curry.js");
|
---|
8 | /**
|
---|
9 | * Returns the number of items in a given `list` matching the predicate `f`
|
---|
10 | *
|
---|
11 | * @func
|
---|
12 | * @memberOf R
|
---|
13 | * @since v0.28.0
|
---|
14 | * @category List
|
---|
15 | * @sig (a -> Boolean) -> [a] -> Number
|
---|
16 | * @param {Function} predicate to match items against
|
---|
17 | * @return {Array} list of items to count in
|
---|
18 | * @example
|
---|
19 | *
|
---|
20 | * const even = x => x % 2 == 0;
|
---|
21 | *
|
---|
22 | * R.count(even, [1, 2, 3, 4, 5]); // => 2
|
---|
23 | * R.map(R.count(even), [[1, 1, 1], [2, 3, 4, 5], [6]]); // => [0, 2, 1]
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | var count =
|
---|
28 | /*#__PURE__*/
|
---|
29 | curry(function (pred, list) {
|
---|
30 | return _reduce(function (a, e) {
|
---|
31 | return pred(e) ? a + 1 : a;
|
---|
32 | }, 0, list);
|
---|
33 | });
|
---|
34 | module.exports = count; |
---|
Note:
See
TracBrowser
for help on using the repository browser.