Parameter
You can also set the maximum thread count in ColdFusion Administrator. Click Server Settings > Settings and specify the number of threads in Default Maximum Thread Count For Parallel Functions.
Use this function to calculate the sum of values in an array.
The sum of values in an array. If the array parameter value is an empty array, returns zero.
Array functions, Mathematical functions
arraySum(array [, parallel] [, maxThreadCount]) |
ColdFusion (2021 release): Introduced the following parameters:
ColdFusion (2018 release): Introduced named parameters.
ColdFusion (2016 release) Update 3 - Added ignoreUndefined parameter.
|
Parameter |
Description |
|---|---|
|
array |
(Required) Name of an array. |
|
ignoreEmpty |
(Optional) Boolean (true/false) value denoting whether to ignore empty (Null or "") values in the array while adding the elements. False by default. |
|
parallel |
True if you want to enable parallel programming. |
|
maxThreadCount |
The number of threads the function can execute. The number of threads must be between 1-50. If the value exceeds 50, there is an exception. |
<cfscript>
myArray=[921,22,133,40,345,58,-6];
WriteOutput("Sum of values in myArray is:");
WriteOutput(ArraySum(myArray) & "|"); // returns sum of values in myArray
myNewArray=[];
WriteOutput("Sum of values in myNewArray is:");
WriteOutput(ArraySum(myNewArray)); //returns zero since myNewArray is empty
</cfscript>
Output
Sum of values in myArray is:1513|Sum of values in myNewArray is:0
<cfscript>
myarray=ArrayNew(1);
myarray=[-23,56,97,javacast("null",""),"",1,23];
sum=arraysum(myarray,true); //ignoreEmpty=true
writeoutput(sum);
</cfscript>
154
<cfscript>
for(i=1;i<=100000;i++){
if(i === 4500)
arr[i]=0;
else
arr[i]=i*2;
}
sum= arr.map(function(item){
return item/2;
},true,20).sum(false,true,10)
writeoutput(sum & "<br>");
sum = arraysum(array=arr,ignoreempty=true,parallel=true,maxthreadcount=10)
writeoutput(sum & "<br>");
sum1 = arraysum(arr,false,true,10)
writeoutput(sum1 & "<br>");
</cfscript>
Sign in to your account