Hi Jim Phillips ,
Have a look at the snippet below:
var arr = [1,null,3];
Console("sum :" + Sum(arr));
Console("mean:" + Mean(arr));
var tot = 0;
var cnt = 0;
for (var i in arr) {
if (!IsEmpty(arr[i])) {
tot+=arr[i];
cnt+=1;
}
}
var promedio = tot/cnt;
return promedio;
I have an array with 3 values, of which 1 is null. When I use the Sum it will return a correct result, since 1+null+3 = 4. The Mean however will not return the correct result, since the sum 4 will be divided by 3 elements and return 1.333.
To avoid this, you will probably have to loop through the array and only cnt and sum the non-null values. In Arcade you cannot use the list comprehensions that you are showed in your example.