Skip to content

Instantly share code, notes, and snippets.

@owalacesilva
Last active June 13, 2023 13:39
Show Gist options
  • Save owalacesilva/fef1e331a7d251e20dec61a13262562c to your computer and use it in GitHub Desktop.
Save owalacesilva/fef1e331a7d251e20dec61a13262562c to your computer and use it in GitHub Desktop.
Palindrome word
def palindrome?(word)
initial_word = word.downcase.gsub(/[^a-z0-9]/, '')
reversed_word = initial_word.reverse
initial_word == reversed_word
end
puts 'Typing a word:'
input = gets.chomp
if palindrome?(input)
puts "\"#{input}\" is a palindrome word."
else
puts "\"#{input}\" is not a palindrome word."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment