This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
collection.average( )

collection.average( ) 


 

collection.average ( {propertyPath} ) -> Function result 
Parameter Type   Description
propertyPath  Text in Object property path to be used for calculation
Function result  Real, Undefined in Arithmetic mean (average) of collection values

The collection.average( ) method returns the arithmetic mean (average) of defined 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.average( ) returns Undefined 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;6)
 $vAvg:=$col.average() //12

 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))
 $vAvg:=$col.average("salary") //23500

 
PROPERTIES 

Product: 4D
Theme: Collections
Number: 705250

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)