Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
No edit summary |
Langurmonkey (talk | contribs) (→{{header|langur}}: using operator implied function) |
||
Line 1,634: | Line 1,634: | ||
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. |
||
{{works with|langur|0.6.6}} |
|||
<lang langur>val .mean = f(. |
<lang langur>val .mean = f(.x) fold(f{+}, .x) / len(.x) |
||
writeln .mean([7, 3, 12]) |
writeln " custom: ", .mean([7, 3, 12]) |
||
writeln mean([7, 3, 12])</lang> |
writeln "built-in: ", mean([7, 3, 12])</lang> |
||
{{out}} |
{{out}} |
||
<pre>7.333333333333333333333333333333333 |
<pre> custom: 7.333333333333333333333333333333333 |
||
7.333333333333333333333333333333333</pre> |
built-in: 7.333333333333333333333333333333333</pre> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |