This function iterates over every element of the list and calls the closure to work on that element. This function will reduce the list to a single value, from the right to the left, and will return the value.
NOTE: Use caution if using the member function. list.reduceRight
and list.listReduceRight
may behave differently.
NOTE:This function is not available in Lucee 5.x or lower. Potentially use reverse()
instead.
listReduceRight(list, callback, initialValue[, delimiter][, includeEmptyFields])
→ returns any
list.listReduceRight(callback, initialValue[, delimiter][, includeEmptyFields])
result
*
any
:
The result of the reduce operation after the previous iteration.
item
*
any
:
The value for the current iteration's item.
index
*
numeric
:
The current index for the iteration.
list
*
string
:
A reference of the original list.
,
false
true
false
Demonstrate the member function.
myList="a,b,c,d";
newList=myList.listReduceRight(function(prev,next,idx,arr){ return prev & next & idx },"");
writedump(newList);
Expected Result: d4c3b2a1
Demonstrate the behavior when there is an empty element.
myList="a,,,,,b,,,c,,,d";
newList=myList.listReduceRight(function(prev,next,idx){ return prev & next & idx },"");
writedump(newList);
Expected Result: d4c3b2a1
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.