sum function

Syntax

  • float/string sum(array)

Parameters

  1. array—(float[], string[], bool[])

Returns

The sum functions returns

  • the sum of all elements in a float array
    sum( [1,2,3] )                         6
  • or the count of all true elements in a bool array
    sum( [true,false,true] )               2
  • or the concatenation of all elements in a string array
    sum( ["a","b","c"] )                   "abc"

Related

Examples

Count and measure geometric properties

frontLength = sum( comp(fe) { street.front : scope.sx } )

numberSmallFaces = sum( comp(f) { all : geometry.area < 0.1 } )

Cumulative sum

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) ]