Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Functions

Functions

Export assignment reduce2d

  • Reduces the number of dimensions by one of a two-dimensional nested array by applying a function against an accumulator and each element along the innermost dimension and returning the accumulation results as a one-dimensional array.

    Notes

    • The applied function is provided the following arguments:

      • accumulator: accumulated value.
      • value: array element.
      • i: index of the first dimension.
      • j: index of the second dimension.
      • arr: input array.
    throws

    the second argument must have a length equal to the size of the outermost input array dimension

    Parameters

    • arr: ArrayLike<Collection>

      array of arrays

    • initial: ArrayLike<any>

      initial values

    • reducer: Function

      function to apply

    • Optional thisArg: any

      input function context

    Returns Array < any >

    accumulation results

    Example

    var naryFunction = require( `@stdlib/utils/nary-function` );
    var add = require( `@stdlib/math/base/ops/add` );
    
    var arr = [
        [ 1, 2, 3 ],
        [ 4, 5, 6 ]
    ];
    
    var out = reduce2d( arr, [ 0, 0 ], naryFunction( add, 2 ) );
    // returns [ 6, 15 ]