In Ruby, one easy way to check for palindromes would be to write a method such as this:
class String
def palindrome?
self == self.reverse
end
end
But the C++ part of my brain screams that this is likely to be very inefficient. So, today’s kata: test-drive a palindrome? method for String, ensuring (with tests) that it is much faster than the above.
Pingback: Twitter Trackbacks for today’s kata « silk and spinach [silkandspinach.net] on Topsy.com
It’s interesting to perform the same Kata with different design goals. If you are looking for readability and expressing intent then your example is perfect already.
Optimized version would be: First check length. Then match first and last going inwards.