Sha256: 43ba2c06d0bdc9960b7b871ee8d4fab396b2000a6b07f0e598e527f17a32659d
Contents?: true
Size: 499 Bytes
Versions: 9
Compression:
Stored size: 499 Bytes
Contents
require 'enumerator' # Set of basic array math functions. module ArrayMath def aaverage accum = self.asum return nil if accum.nil? || self.size == 0 accum.to_f / self.size end def asum self.map {|i| return nil if i.is_a?(String)} inject(0){ |sum,item| sum + item } end ## Retun array FACTOR smaller. Average values to get smaller def smoothed(factor) self.enum_for(:each_slice, factor).map { |snipit| snipit.compact.aaverage } end end class Array include ArrayMath end
Version data entries
9 entries across 9 versions & 2 rubygems