Method: BBLib.average
- Defined in:
- lib/bblib/core/util/array.rb
.average(ary) ⇒ Object
Takes an array and averages all of the floats and integers within it. Non numeric values are ignored.
31 32 33 34 35 36 |
# File 'lib/bblib/core/util/array.rb', line 31 def self.average(ary) numbers = ary.select { |v| BBLib.is_any?(v, Integer, Float) } numbers.inject(0) do |sum, x| sum += x end / numbers.size.to_f end |