Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Last active December 25, 2015 01:39
Show Gist options
  • Save blairanderson/6896224 to your computer and use it in GitHub Desktop.
Save blairanderson/6896224 to your computer and use it in GitHub Desktop.
remove duplicate 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