마지막 업데이트 날짜
2022년 1월 11일
|
다음에도 적용됨 ColdFusion
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 and will return the value.
Returns
Any
Syntax
ListReduce(list, callback, initialValue, [delimiter, includeEmptyFields])
History
ColdFusion (2018 release): Introduced named parameters.
ColdFusion 11: Added this function.
Parameters
Parameter |
Req/Opt |
Default |
Description |
---|---|---|---|
list | Required | The input list. | |
callback | Required | Closure or a function reference that will be called for each iteration. The arguments passed to the callback are
|
|
initialValue | Optional | Initial value which will be used for the reduce operation. The type is any. | |
delimiter | Optional | comma (,) | The list delimiter. The type is string . |
includeEmptyFields | Optional | false | Include empty values. The type is boolean. |
Example
<cfscript> myList="23,54,87,98,11,35,91"; closure=function(value1,value2){ return (value1+value2/ListLen(myList)); // Calculates the average of the values in the list } MyVal=ListReduce(myList,closure,0); // Initial value is 0 WriteOutput(#myVal#); </cfscript>
Output
57