reduceRight

Modified on Mon, 07 Aug 2023

Description

Apply an expression against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.

Syntax

reduceRight(array, total, element, expression)

Parameters

Input ParameterTypeDescription
arrayArrayThe array reduceRight() was called upon
totalnumberThe initialValue, or the previously returned value of the expression. Normally, the last array element is used as initial value, and the iteration starts from the element before. If an initial value is supplied, this is used, and the iteration starts from last element.
elementanyThe current element being processed in the array
expressionexpressionAn expression to be run for each array element. Its return value becomes the value of the accumulator parameter on the next invocation of expression

Return value

Type
number

Sample

ExampleResultDescription
reduceRight( [ 1, 2, 4 ], total, x, total-x)1Subtract the numbers in the array, starting from the end
reduceRight( [ 1, 2, 4 ], 10, x, total-x)9Subtract the numbers in the array, starting from the end with initial offset of 10

To view all the List functions, click here.