Created
September 11, 2020 15:55
-
-
Save Bodacious/cbc096d734ee347a93b3e5341749ad08 to your computer and use it in GitHub Desktop.
Ruby Palindrome String
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 | |
def palindrome? | |
clean_string = self.gsub(/[^\w]/, '').downcase | |
clean_string == clean_string.reverse | |
end | |
end | |
puts "madam".palindrome? # => true | |
puts "racecar".palindrome? # => true | |
puts "madam, . ".palindrome? # => true | |
puts "02/02/2020".palindrome? # => true | |
puts "11/11/11 11:11".palindrome? # => true | |
puts "Madam, I'm Adam".palindrome? # => true | |
puts "A man, a plan, a canal – Panama".palindrome? # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment