Skip to content

Instantly share code, notes, and snippets.

@texel
Last active December 15, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texel/5307124 to your computer and use it in GitHub Desktop.
Save texel/5307124 to your computer and use it in GitHub Desktop.
class String
def palindrome?
head = 0
tail = length - 1
while head <= tail
# Normalize head
head += 1 while self[head] && (self[head] =~ /\W/)
# Normalize tail
tail -= 1 while self[tail] && (self[tail] =~ /\W/)
return false unless self[head].downcase == self[tail].downcase
head += 1
tail -= 1
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment