Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Interfaces

Functions

Functions

Export assignment group

  • Groups values as arrays associated with distinct keys.

    Notes

    • If provided an empty collection, the function returns an empty object.
    throws

    first and last arguments must be the same length

    Parameters

    • collection: Collection

      collection to group

    • groups: Collection

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

    Returns any

    group results

    Example

    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    var groups = [ 'b', 'b', 'f', 'b' ];
    
    var out = group( arr, groups );
    // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
  • Groups values as arrays associated with distinct keys.

    Notes

    • If provided an empty collection, the function returns an empty object.
    throws

    first and last arguments must be the same length

    Parameters

    • collection: Collection

      collection to group

    • options: Options

      function options

    • groups: Collection

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

    Returns any

    group results

    Example

    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    var groups = [ 'b', 'b', 'f', 'b' ];
    
    var opts = {
        'returns': 'indices'
    };
    
    var out = group( arr, opts, groups );
    // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }

    Example

    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    var groups = [ 'b', 'b', 'f', 'b' ];
    
    var opts = {
        'returns': '*'
    };
    
    var out = group( arr, opts, groups );
    // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }