Merge: doc: fixed some typos and other misc. corrections
[nit.git] / examples / rosettacode / arithmetic_mean.nit
1 #!/usr/bin/env nit
2 #
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
5
6 # Task: Arithmetic mean
7 # SEE: <http://rosettacode.org/wiki/Averages/Arithmetic_mean>
8 module arithmetic_mean
9
10 # Computes the meam or the `array` values.
11 fun mean(array: Array[Float]): Float do
12 var sum = 0.0
13 if array.is_empty then return sum
14 for i in array do sum += i
15 return sum / array.length.to_f
16 end
17
18 print mean([3.0, 1.0, 4.0, 1.0, 5.0, 9.0])
19 print mean([3.0, 1.0, 4.0, 1.0, 5.0])
20 print mean([3.0, 1.0, 4.0, 1.0])
21 print mean([3.0, 1.0, 4.0])
22 print mean([3.0, 1.0])
23 print mean([3.0])
24 print mean(new Array[Float])