Jump to content

Averages/Arithmetic mean: Difference between revisions

→‎{{header|langur}}: using operator implied function
No edit summary
(→‎{{header|langur}}: using operator implied function)
Line 1,634:
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(.arrx) fold(f .x {+ .y}, .arrx) / len(.arrx)
 
writeln " custom: ", .mean([7, 3, 12])
writeln "built-in: ", mean([7, 3, 12])</lang>
 
{{out}}
<pre> custom: 7.333333333333333333333333333333333
built-in: 7.333333333333333333333333333333333</pre>
 
=={{header|Lasso}}==
1,007

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.