sajad torkamani


You want a function that takes a string and returns true if it’s a palindrome or false if it’s not. Something like this:

is_palindrome?('john') // false
is_palindrome?('anna') // true

Here’s how in Ruby:

def is_palindrome?(str)
  reversed_str = str.split('').reverse.join
  reversed_str == str


There are two steps:

  • Reverse string.
  • Check if reversed string is the same as original string.
Tagged: Algorithms