Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
m (→{{header|Sidef}}: updated code) |
||
Line 3,559: | Line 3,559: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">func avg(Array list) { |
<syntaxhighlight lang="ruby">func avg(Array list) { |
||
list.len > 0 || return 0 |
list.len > 0 || return 0 |
||
list.sum / list.len |
list.sum / list.len |
||
} |
} |
||
say avg([ |
say avg([Inf, Inf]) |
||
say avg([3,1,4,1,5,9]) |
say avg([3,1,4,1,5,9]) |
||
say avg([1e+20, 3, 1, 4, 1, 5, 9, -1e+20]) |
say avg([1e+20, 3, 1, 4, 1, 5, 9, -1e+20]) |
||
say avg([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0.11]) |
say avg([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0.11]) |
||
say avg([10, 20, 30, 40, 50, -100, 4.7, -1100]) |
say avg([10, 20, 30, 40, 50, -100, 4.7, -1100])</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Inf |
|||
3.833333333333333333333333333333333333333 |
|||
3.83333333333333333333333333333333333333333333333 |
|||
2.875 |
2.875 |
||
3.674 |
3.674 |
||
-130.6625 |
-130.6625 |
||
</pre> |
|||
=={{header|Slate}}== |
=={{header|Slate}}== |