Sha256: 6a8b62e801de7c9aff31e947f46918e750d32831cfe689d09c4f74fd9bdd2e1c
Contents?: true
Size: 403 Bytes
Versions: 2
Compression:
Stored size: 403 Bytes
Contents
Array.class_eval do def sum_it(attribute) self.map {|x| x.send(attribute) }.compact.sum end def weighted_mean_of_attribute(attribute) self.map {|x| x.send(attribute) }.compact.weighted_mean end def weighted_mean w_sum = sum(self) return 0.00 if w_sum == 0.00 w_prod = 0 self.each_index {|i| w_prod += (i+1) * self[i].to_f} w_prod.to_f / w_sum.to_f end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
conductor-0.9.4 | lib/conductor/core_ext.rb |
conductor-0.9.3 | lib/conductor/core_ext.rb |