Specifies which group an element in the input collection belongs to.
Specifies which group an element in the input collection belongs to.
Specifies which group an element in the input collection belongs to.
Groups values according to an indicator function and returns group counts.
When invoked, the indicator function is provided two arguments:
value
: collection valueindex
: collection indexThe value returned by an indicator function should be a value which can be serialized as an object key.
If provided an empty collection, the function returns an empty object.
input collection
indicator function specifying which group an element in the input collection belongs to
counts
function indicator( v ) {
return v[ 0 ];
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var out = countBy( arr, indicator );
// returns { 'b': 3, 'f': 1 }
Groups values according to an indicator function and returns group counts.
When invoked, the indicator function is provided two arguments:
value
: collection valueindex
: collection indexThe value returned by an indicator function should be a value which can be serialized as an object key.
If provided an empty collection, the function returns an empty object.
input collection
function options
indicator function specifying which group an element in the input collection belongs to
counts
function indicator( v ) {
return v[ 0 ];
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var out = countBy( arr, indicator );
// returns { 'b': 3, 'f': 1 }
Specifies which group an element in the input collection belongs to.
collection value
collection index
object key