[Solved] How to recursively check if a string is palindrome in Ruby [closed]


Smells like homework assignment since you specifically request a recursive solution.

A solution with recursion is to check whether first equals last letter and if they are recursively check the string in between. An empty or one character string is a palindrome.

def palindrome?(str)
    str.length <= 1 or (str[0,1] == str[-1,1] and palindrome?(str[1..-2]))
end

solved How to recursively check if a string is palindrome in Ruby [closed]