avatar

25

add array#sum and #mean methods

by chrisk, 19 Jun, 2007 07:09 PM
11 25  
44 class ApplicationController < ActionController::Base
55   helper :all # include all helpers, all the time
66 end
7 
8 class Array
9   def sum
10     inject(0) { |sum, x| sum + x }
11   end
12   def mean
13     (size > 0) ? sum.to_f / size : 0
14   end
15 end