← Back to Gists

String palindrome check

📝 Ruby
charlesr
charlesr · Level 1 ·

This snippet checks whether a string reads the same forwards and backwards by comparing it to its reversed version.

Ruby
def palindrome?(str) str == str.reverse
end puts palindrome?("racecar")
puts palindrome?("hello")

Comments

No comments yet. Start the discussion.