Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/count-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 countBy

  • Groups values according to an indicator function and returns group counts.

    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

      input collection

    • indicator: Indicator

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

    Returns any

    counts

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var out = countBy( arr, indicator );
    // returns { 'b': 3, 'f': 1 }
  • Groups values according to an indicator function and returns group counts.

    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

      input collection

    • options: Options

      function options

    • indicator: Indicator

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

    Returns any

    counts

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var out = countBy( arr, indicator );
    // returns { 'b': 3, 'f': 1 }