reduceRight()

Apply a reducer Function to each set element, from right to left, to get a single value.

Signature

reduceRight(reducer: (acc: Any, val: Any) => Any): Any

Description

The reduceRight() method applies a reducer Function to each Set element, from right to left, by passing the reducer value returned from the previous iteration and the next Set element as parameters. The result of the last calculation is the value returned by the method.

reduceRight() starts with the last value in the array, passing the last and second to last set values on the first call.

the calling set isn’t changed.

Parameters

Parameter Type Required Description

reducer

Function

Yes

Function to invoke for each element of the calling set.

reducer parameters:

Parameter Type Required Description

acc

Any

Value returned by the previous invocation of reducer.

val

Any

Yes

Current Set element to be evaluated.

Return value

Type Description

Any

Result of the last reducer calculation.

Examples

Reduce the Set elements, right to left:

let iter = [1, 2, 3]
iter.reduceRight((acc, elem) => acc + elem)
6

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!