Averages/Arithmetic mean: Difference between revisions

Content deleted Content added
Franck (talk | contribs)
Line 2,266: Line 2,266:
=={{header|Oforth}}==
=={{header|Oforth}}==


Oforth has a avg method. It returs null is the collection is empty
<lang Oforth>: avg ( x -- avg )
x sum

x size dup ifZero: [ 2drop null ] else: [ >float / ]
<lang Oforth>[1, 2, 2.718, 3, 3.142] avg println
[ ] avg println</lang>
;</lang>


{{out}}
{{out}}
<pre>
<pre>
[1, 2, 2.718, 3, 3.142] avg .
2.372
2.372 ok
null
[ ] avg .
null ok
</pre>
</pre>