Recursive function to check if a string is palindrome | A recursive function that check a str ( s . . e ) is palindrome or not . ; If there is only one character ; If first and last characters do not match ; If there are more than two characters , check if middle substring is also palindrome or not . ; An empty string is considered as palindrome ; Driver Code
function isPalRec ( str , s , e ) { if ( s == e ) return true ; if ( ( str . charAt ( s ) ) != ( str . charAt ( e ) ) ) return false ; if ( s < e + 1 ) return isPalRec ( str , s + 1 , e - 1 ) ; return true ; } function isPalindrome ( str ) { var n = str . length ; if ( n == 0 ) return true ; return isPalRec ( str , 0 , n - 1 ) ; } var str = " " ; if ( isPalindrome ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;