Last active
December 15, 2015 18:49
-
-
Save texel/5307124 to your computer and use it in GitHub Desktop.
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 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