Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Interfaces

Type aliases

Functions

Type aliases

Binary

Binary: (value: any, index: number) => string | symbol

Specifies which group an element in the input collection belongs to.

param

collection value

param

collection index

returns

object key

Type declaration

    • (value: any, index: number): string | symbol
    • Parameters

      • value: any
      • index: number

      Returns string | symbol

Indicator

Indicator: Nullary | Unary | Binary

Specifies which group an element in the input collection belongs to.

param

collection value

param

collection index

returns

object key

Nullary

Nullary: () => string | symbol

Specifies which group an element in the input collection belongs to.

returns

object key

Type declaration

    • (): string | symbol
    • Returns string | symbol

Unary

Unary: (value: any) => string | symbol

Specifies which group an element in the input collection belongs to.

param

collection value

returns

object key

Type declaration

    • (value: any): string | symbol
    • Parameters

      • value: any

      Returns string | symbol

Functions

Export assignment groupBy

  • Groups values according to an indicator function.

    Notes

    • When invoked, the indicator function is provided two arguments:

      • value: collection value
      • index: collection index
    • The 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.

    Parameters

    • collection: Collection

      collection to group

    • indicator: Indicator

      indicator function specifying which group an element in the input collection belongs to

    Returns any

    group results

    Example

    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.

    Notes

    • When invoked, the indicator function is provided two arguments:

      • value: collection value
      • index: collection index
    • The 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.

    Parameters

    • collection: Collection

      collection to group

    • options: Options

      function options

    • indicator: Indicator

      indicator function specifying which group an element in the input collection belongs to

    Returns any

    group results

    Example

    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 ] }

    Example

    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' ] ] }