Averages/Arithmetic mean: Difference between revisions

(→‎{{header|RPL}}: remediated the dc-based version)
(3 intermediate revisions by the same user not shown)
Line 1,981:
We could use fold() to write a function that takes an array and calculates the mean.
 
<syntaxhighlight lang="langur">val .mean = f(fn .x): fold(ffn{+}, .x) / len(.x)
{{works with|langur|0.6.6}}
<syntaxhighlight lang="langur">val .mean = f(.x) fold(f{+}, .x) / len(.x)
 
writeln " custom: ", .mean([7, 3, 12])
1,007

edits