ArrayReduceRight

This function iterates over every element of the array and calls the closure to work on that element.

It will reduce the array to a single value, from the right to the left, and return it.

Method Signature

ArrayReduceRight(array=[array], callback=[function:BiFunction], initialValue=[any])

Arguments

Argument
Type
Required
Description
Default

array

array

true

The array to reduce

callback

function:BiFunction

true

The function to invoke for each item. The function will be passed 3 arguments: the accumulator, the current item, and the current index. You can alternatively pass a Java BiFunction which will only receive the first 2 args. The function should return the new accumulator value.

initialValue

any

false

The initial value of the accumulator

Examples

Simple arrayReduceRight Example

Demonstrate how the function works from right to left.

Run Example

myArray = [ 
	"a",
	"b",
	"c",
	"d"
];
newArray = arrayReduceRight( myArray, ( Any prev, Any next, Any idx, Any arr ) => {
	return prev & next & idx;
}, "" );
writedump( newArray );

Result: d4c3b2a1

Last updated

Was this helpful?