Options
All
  • Public
  • Public/Protected
  • All
Menu

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

frequency table value

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

frequency table value

Nullary

Nullary: () => string | symbol

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

returns

frequency table value

Type declaration

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

TableEntry

TableEntry: [any, number, number]

Three-element array holding a unique value, the value count, and the frequency percentage.

Unary

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

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

param

collection value

returns

frequency table value

Type declaration

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

      • value: any

      Returns string | symbol

Functions

Export assignment tabulateBy

  • Generates a frequency table according to a provided function.

    Notes

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

      • value: collection value
      • index: collection index
    • The output is an array of arrays. Each sub-array corresponds to a unique value in the input collection and is structured as follows:

      • 0: unique value
      • 1: value count
      • 2: frequency percentage
    • If provided an empty collection, the function returns an empty array.

    Parameters

    • collection: Collection

      input collection

    • indicator: Indicator

      function whose return values are used to populate the output frequency table

    Returns Array < TableEntry >

    frequency table

    Example

    function indicator( value ) {
        return value[ 0 ];
    }
    
    var arr = [ 'beep', 'boop', 'foo', 'beep' ];
    
    var out = tabulateBy( arr, indicator );
    // returns [ [ 'b', 3, 0.75 ], [ 'f', 1, 0.25 ] ]
  • Generates a frequency table according to a provided function.

    Notes

    Notes

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

      • value: collection value
      • index: collection index
    • The output is an array of arrays. Each sub-array corresponds to a unique value in the input collection and is structured as follows:

      • 0: unique value
      • 1: value count
      • 2: frequency percentage
    • If provided an empty collection, the function returns an empty array.

    Parameters

    • collection: Collection

      input collection

    • options: Options

      function options

    • indicator: Indicator

      function whose return values are used to populate the output frequency table

    Returns Array < TableEntry >

    frequency table

    Example

    function indicator( value ) {
        return value[ 0 ];
    }
    
    var arr = [ 'beep', 'boop', 'foo', 'beep' ];
    
    var opts = {
        'thisArg': {}
    };
    var out = tabulateBy( arr, opts, indicator );
    // returns [ [ 'b', 3, 0.75 ], [ 'f', 1, 0.25 ] ]