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.
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.
collection to group
indicator function specifying which group an element in the input collection belongs to
group results
function indicator( v ) {
return v[ 0 ];
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var out = groupBy( arr, indicator );
// returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
Groups values according to an indicator function.
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.
collection to group
function options
indicator function specifying which group an element in the input collection belongs to
group results
function indicator( v ) {
return v[ 0 ];
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var opts = {
'returns': 'indices'
};
var out = groupBy( arr, opts, indicator );
// returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }
function indicator( v ) {
return v[ 0 ];
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var opts = {
'returns': '*'
};
var out = groupBy( arr, opts, indicator );
// returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }
Specifies which group an element in the input collection belongs to.
collection value
collection index
object key