4D v18

collection.sum( )

Home

 
4D v18
collection.sum( )

collection.sum( )  


 

The collection.sum( ) method returns the sum for all values in the collection instance.

Only numerical elements are taken into account for the calculation (other element types are ignored).

If the collection contains objects, pass the propertyPath parameter to indicate the object property to take into account.

collection.sum( ) returns 0 if:

  • the collection is empty,
  • the collection does not contain numerical elements,
  • propertyPath is not found in the collection.

 C_COLLECTION($col)
 $col:=New collection(10;20;"Monday";True;2)
 $vsum:=$col.sum() //32

 C_COLLECTION($col)
 $col:=New collection
 $col.push(New object("name";"Smith";"salary";10000))
 $col.push(New object("name";"Wesson";"salary";50000))
 $col.push(New object("name";"Gross";"salary";10500,5))
 $vSum:=$col.sum("salary") //$vSum=70500,5

 
PROPERTIES 

Product: 4D
Theme: Collections

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v18)