Skip to content

Commit

Permalink
Add mean script
Browse files Browse the repository at this point in the history
Treats its arguments as numeric and then outputs the arithmetic mean of
them.
  • Loading branch information
robmiller committed Feb 28, 2017
1 parent 1569106 commit 051ff17
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bin/mean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
#
# Treating all its arguments as numeric, outputs their arithmetic mean.
#
# For example:
#
# $ mean 10 20 30
# 20
#
# $ mean 1 1 1 1 1 1 900
# 129
#
# Author: Rob Miller <r@robm.me.uk>

puts ARGV.map(&:to_i).reduce(:+) / ARGV.length

0 comments on commit 051ff17

Please sign in to comment.