Returns a boolean indicating which group an element in an collection belongs to.
Returns a boolean indicating which group an element in an collection belongs to.
Returns a boolean indicating which group an element in an collection belongs to.
Splits values into two groups according to a predicate function.
When invoked, the predicate function is provided two arguments:
value
: collection valueindex
: collection indexIf a predicate function returns a truthy value, a collection value is placed in the first group; otherwise, a collection value is placed in the second group.
If provided an empty collection, the function returns an empty array.
input collection
predicate function indicating which group an element in the input collection belongs to
group results
function predicate( v ) {
return v[ 0 ] === 'b';
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var out = bifurcateBy( arr, predicate );
// returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
Splits values into two groups according to a predicate function.
When invoked, the predicate function is provided two arguments:
value
: collection valueindex
: collection indexIf a predicate function returns a truthy value, a collection value is placed in the first group; otherwise, a collection value is placed in the second group.
If provided an empty collection, the function returns an empty array.
input collection
function options
predicate function indicating which group an element in the input collection belongs to
group results
function predicate( v ) {
return v[ 0 ] === 'b';
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var opts = {
'returns': 'indices'
};
var out = bifurcateBy( arr, opts, predicate );
// returns [ [ 0, 1, 3 ], [ 2 ] ]
function predicate( v ) {
return v[ 0 ] === 'b';
}
var arr = [ 'beep', 'boop', 'foo', 'bar' ];
var opts = {
'returns': '*'
};
var out = bifurcateBy( arr, opts, predicate );
// returns [ [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], [ [ 2, 'foo' ] ] ]
Returns a boolean indicating which group an element in an collection belongs to.
collection value
collection index
boolean indicating whether an element in a collection should be placed in the first or second group