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 Parameter | Type | Description |
---|---|---|
array | Array | The array reduceRight() was called upon |
total | number | The 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. |
element | any | The current element being processed in the array |
expression | expression | An 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
Example | Result | Description |
---|---|---|
reduceRight( [ 1, 2, 4 ], total, x, total-x) | 1 | Subtract the numbers in the array, starting from the end |
reduceRight( [ 1, 2, 4 ], 10, x, total-x) | 9 | Subtract the numbers in the array, starting from the end with initial offset of 10 |
To view all the List functions, click here.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article