Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created July 7, 2019 23:21
Show Gist options
  • Save jubishop/35703f079fb097d1172c83b09315f457 to your computer and use it in GitHub Desktop.
Save jubishop/35703f079fb097d1172c83b09315f457 to your computer and use it in GitHub Desktop.
class String
include Enumerable
def each
each_char { |char| yield char }
end
end
def compress_string(string)
string.chunk{|x|x}.map { |char, ary| ary.length > 1 ? "#{char}#{ary.length}" : char }.join('')
end
puts compress_string("aaabbbaaaccc")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment