What about
array = [1, 1, 1, 0, 0, 1, 1, 1, 1, 0]
array.split(0).group_by(&:size).max.first #=> 4
The only bad thing is split(0)
Note. This only works with ActiveSupport rails (extends C # split array)
Only for implementation with ruby ββonly
array.join.split("0").group_by(&:size).max.first #=> 4
source share