ListReduceRight

Description

Iterates over each item of the list and calls the closure to work on the item. This function will reduce the list to a single value from right to left and will return the value.

Returns

Any

Syntax

ListReduceRight(list, callback, initialValue, [delimiter, includeEmptyFields])

History

ColdFusion (2021 release): Added this function.

Parameters

Parameter

Required/Optional

Description

array

Required

The input array.

callback

Required

Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are

  • result: result of the reduce operation after the previous iteration
  • item: item in the array
  • index : current index for the iteration
  • array : reference of the original array

initialValue

Optional

Initial value which will be used for the reduce operation. The type is any.

delimiter

Optional

The list delimiter. The type is string.

includeEmptyFields

Optional

(Boolean) Include empty values. 

Example

<cfscript> 
    myList="2021, ColdFusion "; 
    closure=function(value1,value2){ 
             return (value1&value2); 
       } 
       writeOutput(ListReduce(myList,closure,"")); 
       writeoutput("<br>") 
       writeOutput(ListReduceRight(myList,closure,"")); 
</cfscript>

Output

2021 ColdFusion
ColdFusion 2021

Example- Member function

<cfscript> 
    myList="2021, ColdFusion "; 
    closure=function(value1,value2){ 
             return (value1&value2); 
       } 
      writeOutput(myList.ReduceRight(closure,"")); 
</cfscript>

Output

noisuFdloC ,1202

Adobe logo

Sign in to your account