Class: StatisticalMethods::Leader
- Inherits:
-
Object
- Object
- StatisticalMethods::Leader
- Defined in:
- lib/statistical_methods/leader.rb
Overview
Finding a leader in the collection
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(array) ⇒ Leader
constructor
A new instance of Leader.
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
#find ⇒ Object
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 |