Sha256: c1f892e47d024b5c42912e2ec476149ee4b3d39f6a2ac3f653773957662e312e
Contents?: true
Size: 364 Bytes
Versions: 18
Compression:
Stored size: 364 Bytes
Contents
module PassiveRecord module ArithmeticHelpers def pluck(attr) all.map(&attr) end def sum(attr) pluck(attr).inject(&:+) end def average(attr) sum(attr) / count end def mode(attr) arr = pluck(attr) freq = arr.inject(Hash.new(0)) { |h,v| h[v] += 1; h } arr.max_by { |v| freq[v] } end end end
Version data entries
18 entries across 18 versions & 1 rubygems