Created
July 7, 2019 23:21
-
-
Save jubishop/35703f079fb097d1172c83b09315f457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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