Skip to content

Instantly share code, notes, and snippets.

@udzura
Created October 21, 2009 05:37
Show Gist options
  • Save udzura/214898 to your computer and use it in GitHub Desktop.
Save udzura/214898 to your computer and use it in GitHub Desktop.
def hyphenize_numbers2 *args
puts args.map{|v| v.to_i}.sort.uniq.unshift(nil).enum_for(:each_cons, 2).inject([]){|dst, src| dst.push((!src[0] || src[1] - src[0] > 1) ? [src[1]] : dst.pop.push(src[1]))}.map{|nums| nums.length == 1 ? nums[0].to_s : "#{nums.first}-#{nums.last}"}.join(", ") + "."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment