语法
- float/string sum(array)
参数
- array - (float[], string[], bool[])
返回
sum 函数可返回
- 浮点数组中所有元素的总和
sum( [1,2,3] ) 6
- 或布尔数组中所有 true 元素的计数
sum( [true,false,true] ) 2
- 或字符串数组中所有元素的串连
sum( ["a","b","c"] ) "abc"
相关内容
示例
计算和测量几何属性
frontLength = sum( comp(fe) { street.front : scope.sx } )
numberSmallFaces = sum( comp(f) { all : geometry.area < 0.1 } )
累计总和
const x = cumsum([1:5]) // [1,3,6,10,15]
const y = cumsum(["a","b","c","d","e"]) // [a,ab,abc,abcd,abcde]
const z = cumsum([false,true,true,false,true]) // [0,1,2,2,3]
cumsum(array) = case size(array) < 2 : [ sum(array) ]
else : [ cumsum(array[0:size(array)-2]), sum(array) ]