Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Type aliases

ArrayQuaternary

ArrayQuaternary: (accumulator: any, value: any, index: number, arr: Collection) => any

Function applied against an accumulator.

param

accumulated value

param

array element

param

element index

param

array

returns

accumulator value

Type declaration

    • (accumulator: any, value: any, index: number, arr: Collection): any
    • Parameters

      • accumulator: any
      • value: any
      • index: number
      • arr: Collection

      Returns any

ArrayReducer

Function applied against an accumulator.

param

accumulated value

param

array element

param

element index

param

array

returns

accumulator value

Binary

Binary: (accumulator: any, value: any) => any

Function applied against an accumulator.

param

accumulated value

param

array element

returns

accumulator value

Type declaration

    • (accumulator: any, value: any): any
    • Parameters

      • accumulator: any
      • value: any

      Returns any

Nullary

Nullary: () => void

Function applied against an accumulator.

returns

accumulator value

Type declaration

    • (): void
    • Returns void

Quaternary

Quaternary: (accumulator: any, value: any, index: number, arr: ndarray) => any

Function applied against an accumulator.

param

accumulated value

param

array element

param

element index

param

array

returns

accumulator value

Type declaration

    • (accumulator: any, value: any, index: number, arr: ndarray): any
    • Parameters

      • accumulator: any
      • value: any
      • index: number
      • arr: ndarray

      Returns any

Reducer

Function applied against an accumulator.

param

accumulated value

param

array element

param

element index

param

array

returns

accumulator value

Ternary

Ternary: (accumulator: any, value: any, index: number) => any

Function applied against an accumulator.

param

accumulated value

param

array element

param

element index

returns

accumulator value

Type declaration

    • (accumulator: any, value: any, index: number): any
    • Parameters

      • accumulator: any
      • value: any
      • index: number

      Returns any

Unary

Unary: (accumulator: any) => any

Function applied against an accumulator.

param

accumulated value

returns

accumulator value

Type declaration

    • (accumulator: any): any
    • Parameters

      • accumulator: any

      Returns any

Functions

Export assignment reduce

  • Applies a function against an accumulator and each element in an array and returns the accumulated result.

    Notes

    • The reduction function is provided four arguments:

      • accumulator: accumulated value.
      • value: array element.
      • index: element index.
      • arr: input array.
    • If provided an empty array, the function returns the initial value.

    Parameters

    • arr: ndarray

      input array

    • initial: any

      initial value

    • reducer: Reducer

      reduction function

    • Optional thisArg: any

      reduction function execution context

    Returns any

    accumulated result

    Example

    var naryFunction = require( `@stdlib/utils/nary-function` );
    var add = require( `@stdlib/math/base/ops/add` );
    var array = require( `@stdlib/ndarray/array` );
    
    var opts = {
        'dtype': 'generic'
    };
    var arr = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );
    
    var out = reduce( arr, 0, naryFunction( add, 2 ) );
    // returns 21
  • Applies a function against an accumulator and each element in an array and returns the accumulated result.

    Notes

    • The reduction function is provided four arguments:

      • accumulator: accumulated value.
      • value: array element.
      • index: element index.
      • arr: input array.
    • If provided an empty array, the function returns the initial value.

    Parameters

    • arr: Collection

      input array

    • initial: any

      initial value

    • reducer: ArrayReducer

      reduction function

    • Optional thisArg: any

      reduction function execution context

    Returns any

    accumulated result

    Example

    function sum( acc, value ) {
        return acc + value;
    }
    
    var arr = [ 1, 2, 3, 4 ];
    
    var out = reduce( arr, 0, sum );
    // returns 10