Check if both halves of a string are Palindrome or not | Function to check and return if both halves of a string are palindromic or not ; Length of string ; Initialize both part as true ; If first half is not palindrome ; If second half is not palindrome ; If both halves are Palindrome ; Driver Code
function checkPalindrome ( S ) { var N = S . length ; var first_half = true ; var second_half = true ; var cnt = parseInt ( ( N / 2 ) ) - 1 ; for ( i = 0 ; i < ( N / 2 ) ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( cnt ) ) { first_half = false ; break ; } if ( S . charAt ( N / 2 + i ) != S . charAt ( N / 2 + cnt ) ) { second_half = false ; break ; } cnt -- ; } if ( first_half && second_half ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var S = " " ; checkPalindrome ( S ) ;