Module: MoreCoreExtensions::ArrayMath

Defined in:
lib/more_core_extensions/core_ext/array/math.rb

Instance Method Summary collapse

Instance Method Details

#meanObject

Returns the mean of an Array of Numerics.

[1, 2, 3, 4, 5].mean  #=> 3.0
[1.0, 2.0, 3.0].mean  #=> 2.0


12
13
14
# File 'lib/more_core_extensions/core_ext/array/math.rb', line 12

def mean
  sum.to_f / length
end

#stddevObject

Returns the standard deviation of an Array of Numerics.

[1, 2, 3, 4, 5].stddev  #=> 1.5811388300841898
[1.0, 2.0, 3.0].stddev  #=> 1.0


21
22
23
# File 'lib/more_core_extensions/core_ext/array/math.rb', line 21

def stddev
  Math.sqrt(variance)
end

#varianceObject

Returns the variance of an Array of Numerics.

[1, 2, 3, 4, 5].variance  #=> 2.5
[1.0, 2.0, 3.0].variance  #=> 1.0


30
31
32
33
# File 'lib/more_core_extensions/core_ext/array/math.rb', line 30

def variance