Created
May 31, 2016 14:40
-
-
Save serghost/a1c39106941a41e51c94266f7174bc6c 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 is_palindrome? | |
str = self.gsub(/[^a-zA-Z]/i, '').downcase | |
str_size = str.size | |
raise "Incorrect string" if str_size < 2 | |
half_string_1 = str.slice(0...str_size/2) | |
half_string_2 = str.slice(-(str_size/2)..-1) | |
if half_string_2 == half_string_1 | |
puts "It's a palindrome" | |
else | |
puts "It's not a palindrome" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I could write better lol. Even if using the
reverse
method is prohibitedt.2020