Icard/angular-clarity-master(work.../node_modules/ramda/es/count.js

28 lines
709 B
JavaScript
Raw Normal View History

2024-07-16 15:23:22 +00:00
import _reduce from "./internal/_reduce.js";
import curry from "./curry.js";
/**
* Returns the number of items in a given `list` matching the predicate `f`
*
* @func
* @memberOf R
* @since v0.28.0
* @category List
* @sig (a -> Boolean) -> [a] -> Number
* @param {Function} predicate to match items against
* @return {Array} list of items to count in
* @example
*
* const even = x => x % 2 == 0;
*
* R.count(even, [1, 2, 3, 4, 5]); // => 2
* R.map(R.count(even), [[1, 1, 1], [2, 3, 4, 5], [6]]); // => [0, 2, 1]
*/
var count =
/*#__PURE__*/
curry(function (pred, list) {
return _reduce(function (a, e) {
return pred(e) ? a + 1 : a;
}, 0, list);
});
export default count;