avg

Modified on Thu, 9 Jul at 10:48 AM

avg

TABLE OF CONTENTS

Find the average of an array of numbers

Definition

number avg(array[number] $elements)

Returns the arithmetic mean of the elements in the provided array.

Parameters

array[number] $elements

The numbers to find the arithmetic mean of.

Returns

number

The arithmetic mean of the elements in $elements.

Examples

Transformation
{
  numAvg: avg([`1`,`2`,`3`]), 
  decimalStringAvg: avg(['1.5',`2.1`,`2.9`]),
  boolAvg: avg([`true`,`false`]),
  nullAvg: avg([`1`,`2`,`null`]),
  emptyAvg: avg([]),           // Error
  textAvg: avg(['a', 'b']),    // Error
  noArrayAvg: avg(`5`)         // Error
}
Result
{
  "numAvg": 2.0,
  "decimalAvg": 2.1666666666666665,
  "boolAvg": 0.5,
  "nullAvg": 1.0
}

Remarks

null, true and false are all converted to their numerical values; no errors are raised if they appear in $elements.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article