WKC CCC wrote:
> Does anyone know of a function that multiplies the contents of an array.
module Enumerable
def product
inject{ |piece, prod| prod*piece }
end
def sum
inject(0){ |piece, total| total+piece }
end
end
a = (1..10)
p a.sum
#=> 55
p a.product
#=> 3628800