Skip to content

Instantly share code, notes, and snippets.

@you-ssk
Created November 9, 2012 09:26
Show Gist options
  • Save you-ssk/4044755 to your computer and use it in GitHub Desktop.
Save you-ssk/4044755 to your computer and use it in GitHub Desktop.
def format(a)
a.inject([a.shift]){|r,e|
if r[-1] == e-1
r.pop(2) if r[-2] == '-'
r << '-'
else
r << ','
end
r << e
}.join.squeeze('-')
end
a = [1,2,3,5,6,7]
p format(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment