Class: StatisticalMethods::Leader

Inherits:
Object
  • Object
show all
Defined in:
lib/statistical_methods/leader.rb

Overview

Finding a leader in the collection

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Leader

Returns a new instance of Leader.



4
5
6
7
8
# File 'lib/statistical_methods/leader.rb', line 4

def initialize(array)
  @array = array
  @candidate = array.first
  @counter = 0
end

Instance Method Details

#findObject



10
11
12
13
# File 'lib/statistical_methods/leader.rb', line 10

def find
  @array.each { |value| compare(value) }
  @candidate if @array.count(@candidate) > @array.size / 2
end