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


10
11
12
# File 'lib/more_core_extensions/core_ext/array/math.rb', line 10

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


19
20
21
# File 'lib/more_core_extensions/core_ext/array/math.rb', line 19

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


28
29
30
31
# File 'lib/more_core_extensions/core_ext/array/math.rb', line 28

def variance