Class: R0man::MaximumConsecutiveCount
- Inherits:
-
Object
- Object
- R0man::MaximumConsecutiveCount
- Defined in:
- lib/r0man/maximum_consecutive_count.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.for(array) ⇒ Object
4 5 6 |
# File 'lib/r0man/maximum_consecutive_count.rb', line 4 def for(array) MaximumConsecutiveCount.new.for(array) end |
Instance Method Details
#for(array) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/r0man/maximum_consecutive_count.rb', line 9 def for(array) counts = Hash.new(0) current_count = 1 (array + [Float::NAN]).each_cons(2) do |item, next_item| if item == next_item current_count += 1 else current_count = 1 end counts[item] = current_count if current_count > counts[item] end counts end |