Skip to content

Instantly share code, notes, and snippets.

@serghost
Created May 31, 2016 14:40
Show Gist options
  • Save serghost/a1c39106941a41e51c94266f7174bc6c to your computer and use it in GitHub Desktop.
Save serghost/a1c39106941a41e51c94266f7174bc6c to your computer and use it in GitHub Desktop.
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
@serghost
Copy link
Author

I could write better lol. Even if using the reverse method is prohibited
t.2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment