math.arrayMedian: Difference between revisions
Jump to navigation
Jump to search
m (Conversion script moved page math.arrayMedian to Math.arrayMedian without leaving a redirect: Converting page title to first-letter uppercase) |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 6: | Line 6: | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: result = math.arrayMedian(array)] | [h: result = math.arrayMedian(array)] | ||
</ | </syntaxhighlight> | ||
|examples= | |examples= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: array1 = json.append("", 3, 6, 2, 2)] | [h: array1 = json.append("", 3, 6, 2, 2)] | ||
[r: math.arrayMedian(array1)] | [r: math.arrayMedian(array1)] | ||
[h: array2 = json.append("", 12, 23, 3, 102, 1)] | [h: array2 = json.append("", 12, 23, 3, 102, 1)] | ||
[r: math.arrayMedian(array2)] | [r: math.arrayMedian(array2)] | ||
</ | </syntaxhighlight> | ||
Returns: | Returns: | ||
<pre> | <pre> |
Latest revision as of 23:59, 14 March 2023
math.arrayMedian() Function
• Introduced in version 1.7
Calculates the Median of the contents of a JSON Array. The median value is is the value where half the numbers in the array are greater than or equal to it, and the other half are less than or equal to it. The median is calculated by sorting the array contents and picking the middle number if the number of elements is odd, or averaging the two in the middle if the number of elements is even. Only allows numeric elements - any non-numeric values will produce an error.
Usage
[h: result = math.arrayMedian(array)]
Examples
[h: array1 = json.append("", 3, 6, 2, 2)]
[r: math.arrayMedian(array1)]
[h: array2 = json.append("", 12, 23, 3, 102, 1)]
[r: math.arrayMedian(array2)]
Returns:
2.5 12