count-by

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
2 KB
Counts the elements of a list according to how many match each value of a key generated by the supplied function.
1 contributor
Install count-by as a package?
Copied
npm i @bit/justin-capalbo.ramda.count-by
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
countBy (
fn:Function,
list:Array
) : Object

Counts the elements of a list according to how many match each value of a key generated by the supplied function. Returns an object mapping the keys produced by fn to the number of occurrences in the list. Note that all keys are coerced to strings because of how JavaScript objects work.

Acts as a transducer if a transformer is given in list position.

Example
const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
     R.countBy(Math.floor)(numbers);    //=> {'1': 3, '2': 2, '3': 1}

     const letters = ['a', 'b', 'A', 'a', 'B', 'c'];
     R.countBy(R.toLower)(letters);   //=> {'a': 3, 'b': 2, 'c': 1}
Arguments
fn: Function

The function used to map values to keys.

list: Array

The list to count elements from.

Returns
Object

An object mapping keys to number of occurrences in the list.

Help and resources