function isPalindrome(s) {
if (s.length <= 1) return true;
return s[0] === s[s.length - 1] && isPalindrome(s.slice(1, -1));
}
isPalindrome('racecar'); // trueCheck palindromes recursively by comparing outer characters and moving inward.
A palindrome is a string that reads the same forwards and backwards (ignoring spaces and punctuation in real applications).
"racecar" is a palindrome
"hello" is not a palindrome
"a" is a palindrome
"" is a palindrome
Use recursion: if the first and last characters match, recursively check the middle substring.
function isPalindrome(s: string): boolean {
// Return true if s is a palindrome
}
isPalindrome('racecar') // true
isPalindrome('hello') // false