I\'d like to take input such as:
[1,2,4,5,6,7,9,13]
and turn it into something like the following:
[[1,2],[4,7],[9,9],[13,1
Another approach
def summarize(x) x.inject([]) do |acc, value| if acc.last && acc.last[1] + 1 == value acc.last[1] = value acc else acc << [value,value] end end end
Similar to Larsenal's method but using inject to manage the boring stuff.