Module: StatisticalMethods::Core::Array

Included in:
Array
Defined in:
lib/statistical_methods/core/array.rb

Overview

Extending class

Instance Method Summary collapse

Instance Method Details

#additionObject



5
6
7
# File 'lib/statistical_methods/core/array.rb', line 5

def addition
  reduce(:+)
end

#group_by_countObject



21
22
23
24
25
26
# File 'lib/statistical_methods/core/array.rb', line 21

def group_by_count
  reduce(Hash.new(0)) do |hash, item|
    hash[item] += 1
    hash
  end
end

#harmonicObject



17
18
19
# File 'lib/statistical_methods/core/array.rb', line 17

def harmonic
  map { |value| 1.0 / value }
end

#multiplicationObject



9
10
11
# File 'lib/statistical_methods/core/array.rb', line 9

def multiplication
  reduce(:*)
end

#power(exponent) ⇒ Object



13
14
15
# File 'lib/statistical_methods/core/array.rb', line 13

def power(exponent)
  map { |value| value**exponent }
end