Module: Enumerable
- Defined in:
- lib/zombie_check/core_ext/ennumerable.rb
Instance Method Summary collapse
Instance Method Details
#mean ⇒ Object
7 8 9 10 11 |
# File 'lib/zombie_check/core_ext/ennumerable.rb', line 7 def mean # rubocop bug, other way it dies https://github.com/bbatsov/rubocop/issues/3169 return -1 if send(:length) == 0 sum / length.to_f end |
#median ⇒ Object
20 21 22 23 24 25 |
# File 'lib/zombie_check/core_ext/ennumerable.rb', line 20 def median return -1 if send(:length) == 0 middle = length / 2 sorted = sort length.even? ? (sorted[middle] + sorted[middle - 1]) / 2 : sorted[middle] end |
#sigma ⇒ Object
13 14 15 16 17 18 |
# File 'lib/zombie_check/core_ext/ennumerable.rb', line 13 def sigma return -1 if length < 2 m = mean sum = inject(0) { |accum, i| accum + (i - m)**2 } Math.sqrt(sum / (length - 1).to_f) end |
#sum ⇒ Object
3 4 5 |
# File 'lib/zombie_check/core_ext/ennumerable.rb', line 3 def sum inject(0) { |accum, i| accum + i } end |