Class: StatisticalMethods::SummaryStatistic::Location::Mode

Inherits:
Object
  • Object
show all
Defined in:
lib/statistical_methods/summary_statistic/location/mode.rb

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Mode

Returns a new instance of Mode.



5
6
7
# File 'lib/statistical_methods/summary_statistic/location/mode.rb', line 5

def initialize(array)
  @array = array
end

Instance Method Details

#findObject



9
10
11
12
13
14
# File 'lib/statistical_methods/summary_statistic/location/mode.rb', line 9

def find
  return if @array.empty?
  hash = @array.group_by_count
  max = hash.values.max
  hash.keep_if { |_key, value| value == max }.keys
end