Averages/Arithmetic mean: Difference between revisions

Content added Content deleted
Line 259: Line 259:
! dividing by the length of the column, which is the number of rows (SIZE of dimension 1)</lang>
! dividing by the length of the column, which is the number of rows (SIZE of dimension 1)</lang>



=={{header|Groovy}}==
<lang groovy>def avg = { list -> list == [] ? 0 : list.sum() / list.size() }</lang>

Test Program:
<lang groovy>println avg(0..9)
println avg([2,2,2,4,2])
println avg ([])</lang>

Output:
<pre>4.5
2.4
0</pre>


=={{header|Haskell}}==
=={{header|Haskell}}==