Module: Robut::Plugin::Quiz::Range::Averages

Defined in:
lib/range.rb

Instance Method Summary collapse

Instance Method Details

#meanObject



61
62
63
64
# File 'lib/range.rb', line 61

def mean
  return 0 if length == 0
  sum.to_f / length.to_f
end

#modeObject



66
67
68
69
# File 'lib/range.rb', line 66

def mode
  frequency = inject(Hash.new(0)) { |hash,value| hash[value] += 1; hash }
  sort_by {|value| frequency[value] }.last
end

#sumObject



57
58
59
# File 'lib/range.rb', line 57

def sum
  inject(:+)
end