Module: Darthjee::CoreExt::Math
- Included in:
- Math
- Defined in:
- lib/darthjee/core_ext/math.rb
Instance Method Summary collapse
-
#average(values) ⇒ ::Float
Calculates avarage from a series of values.
Instance Method Details
#average(values) ⇒ ::Float #average(values) ⇒ ::Float
Calculates avarage from a series of values
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/darthjee/core_ext/math.rb', line 26 def average(values) if values.is_a?(Hash) weight_sum = values.values.sum values = values.map { |value, weight| value * weight } else weight_sum = values.length end values.sum / weight_sum.to_f end |