I'm going through some exercises on App Academy Open, and I've come across a test case that I can't quite figure out. I've written a method to detect if a given string is a palindrome or not, and it seems to work fine for all strings I've thrown at it - apart from 'xabcx'. Am I missing something?
def palindrome?(str)
(str.length / 2).times do |idx|
if str[idx - 1] != str[idx * -1]
return false
end
end
true
end
p palindrome?("xabcx")
I expect an output of false
, but I get true
. The method works as expected for every other word I've tried.