Skip to content

Averages/Arithmetic mean

editable example

Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.

ghul
use IO.Std.write_line
use Collections
use Ghul.Pipes
mean(values: List[double]) -> double =>
values |> reduce(0.0D, (total, value) => total + value) /
cast(values.count)
write_line("mean: {mean([1.0D, 2.0D, 3.0D, 4.0D, 5.0D]):F1}")
mean: 3.0