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

Version Path
teich-hrmparser-0.4.5 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.6 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.7 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.8 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.9 lib/hrmparser/arraymath.rb
teich-hrmparser-0.5.0 lib/hrmparser/arraymath.rb
teich-hrmparser-0.6.0 lib/hrmparser/arraymath.rb
hrmparser-0.7.0 lib/hrmparser/arraymath.rb
hrmparser-0.6.0 lib/hrmparser/arraymath.rb