math.arrayMean: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page Math.arrayMean to math.arrayMean: Converting page titles to lowercase)
No edit summary
Line 6: Line 6:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: result = math.arrayMean(array)]
[h: result = math.arrayMean(array)]
</source>
</syntaxhighlight>


|examples=
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: theArray = json.append("", 1, 2, 3, 3, 10)]
[h: theArray = json.append("", 1, 2, 3, 3, 10)]
[r: math.arrayMean(theArray)]
[r: math.arrayMean(theArray)]
</source>
</syntaxhighlight>
Returns:
Returns:
<code>3.8</code>
<code>3.8</code>

Revision as of 17:51, 15 March 2023

math.arrayMean() Function

Introduced in version 1.7
Calculates the arithmetic mean of the contents of a JSON Array. Only allows numeric elements - any non-numeric values will produce an error. The mean is equal to the sum of all the array's contents divided by the number of elements.

Usage

[h: result = math.arrayMean(array)]

Examples

[h: theArray = json.append("", 1, 2, 3, 3, 10)]
[r: math.arrayMean(theArray)]

Returns:

3.8