main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | var reduceBy =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./reduceBy.js");
|
---|
4 | /**
|
---|
5 | * Counts the elements of a list according to how many match each value of a
|
---|
6 | * key generated by the supplied function. Returns an object mapping the keys
|
---|
7 | * produced by `fn` to the number of occurrences in the list. Note that all
|
---|
8 | * keys are coerced to strings because of how JavaScript objects work.
|
---|
9 | *
|
---|
10 | * Acts as a transducer if a transformer is given in list position.
|
---|
11 | *
|
---|
12 | * @func
|
---|
13 | * @memberOf R
|
---|
14 | * @since v0.1.0
|
---|
15 | * @category Relation
|
---|
16 | * @sig (a -> String) -> [a] -> {*}
|
---|
17 | * @param {Function} fn The function used to map values to keys.
|
---|
18 | * @param {Array} list The list to count elements from.
|
---|
19 | * @return {Object} An object mapping keys to number of occurrences in the list.
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
|
---|
23 | * R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1}
|
---|
24 | *
|
---|
25 | * const letters = ['a', 'b', 'A', 'a', 'B', 'c'];
|
---|
26 | * R.countBy(R.toLower)(letters); //=> {'a': 3, 'b': 2, 'c': 1}
|
---|
27 | */
|
---|
28 |
|
---|
29 |
|
---|
30 | var countBy =
|
---|
31 | /*#__PURE__*/
|
---|
32 | reduceBy(function (acc, elem) {
|
---|
33 | return acc + 1;
|
---|
34 | }, 0);
|
---|
35 | module.exports = countBy; |
---|
Note:
See
TracBrowser
for help on using the repository browser.