Function applied against an accumulator.
Function applied against an accumulator.
Function applied against an accumulator.
Function applied against an accumulator.
Function applied against an accumulator.
Function applied against an accumulator.
Function applied against an accumulator.
Applies a function against an accumulator and each element in an array while iterating from right to left and returns the accumulated result.
The reduction function is provided four arguments:
If provided an empty array, the function returns the initial value.
input array
initial value
reduction function
reduction function execution context
accumulated result
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 = reduceRight( arr, 0, naryFunction( add, 2 ) );
// returns 21
Applies a function against an accumulator and each element in an array while iterating from right to left and returns the accumulated result.
The reduction function is provided four arguments:
If provided an empty array, the function returns the initial value.
input array
initial value
reduction function
reduction function execution context
accumulated result
function sum( acc, value ) {
return acc + value;
}
var arr = [ 1, 2, 3, 4 ];
var out = reduceRight( arr, 0, sum );
// returns 10
Function applied against an accumulator.
accumulated value
array element
element index
array
accumulator value