Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/bifurcate/docs/types/index.d"

Index

Interfaces

Functions

Functions

Export assignment bifurcate

  • Splits values into two groups.

    Notes

    • If an element in filter is truthy, then the corresponding element in the input collection belongs to the first group; otherwise, the collection element belongs to the second group.
    • If provided an empty collection, the function returns an empty array.
    throws

    first and last arguments must be the same length

    Parameters

    • collection: Collection

      input collection

    • filter: Collection

      collection indicating which group an element in the input collection belongs to

    Returns Array < Array < any > > | Array < any >

    results

    Example

    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    var filter = [ true, true, false, true ];
    
    var out = bifurcate( arr, filter );
    // returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
  • Splits values into two groups.

    Notes

    • If an element in filter is truthy, then the corresponding element in the input collection belongs to the first group; otherwise, the collection element belongs to the second group.
    • If provided an empty collection, the function returns an empty array.
    throws

    first and last arguments must be the same length

    Parameters

    • collection: Collection

      input collection

    • options: Options

      function options

    • filter: Collection

      collection indicating which group an element in the input collection belongs to

    Returns Array < Array < any > > | Array < any >

    results

    Example

    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    var filter = [ true, true, false, true ];
    
    var opts = {
        'returns': 'indices'
    };
    
    var out = bifurcate( arr, opts, filter );
    // returns [ [ 0, 1, 3 ], [ 2 ] ]

    Example

    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    var filter = [ true, true, false, true ];
    
    var opts = {
        'returns': '*'
    };
    
    var out = bifurcate( arr, opts, filter );
    // returns [ [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], [ [ 2, 'foo' ] ] ]