Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
Line 1,981: | Line 1,981: | ||
We could use fold() to write a function that takes an array and calculates the mean. |
We could use fold() to write a function that takes an array and calculates the mean. |
||
<syntaxhighlight lang="langur">val |
<syntaxhighlight lang="langur">val umean = fn x:fold(fn{+}, x) / len(x) |
||
writeln " custom: ", |
writeln " custom: ", umean([7, 3, 12]) |
||
writeln "built-in: ", mean([7, 3, 12]) |
writeln "built-in: ", mean([7, 3, 12]) |
||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |