Last active
December 25, 2015 01:39
-
-
Save blairanderson/6896224 to your computer and use it in GitHub Desktop.
remove duplicate characters
This file contains 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 Word | |
attr_reader :count, :word | |
def initialize(word) | |
@word = word | |
@count = word.length | |
end | |
def simplified | |
count.times do | |
match = word.match(/(\w)\1+/) | |
@word = word.gsub(match[0], match[1]) if match | |
end | |
@word | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment