Jump to content

Averages/Arithmetic mean: Difference between revisions

 
Line 1,981:
We could use fold() to write a function that takes an array and calculates the mean.
 
<syntaxhighlight lang="langur">val .meanumean = fn .x: fold(fn{+}, .x) / len(.x)
 
writeln " custom: ", .meanumean([7, 3, 12])
writeln "built-in: ", mean([7, 3, 12])</syntaxhighlight>
</syntaxhighlight>
 
{{out}}
990

edits

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