Check if a given string is Even | Function to check if the string str is palindromic or not ; Pointers to iterate the string from both ends ; If characters are found to be distinct ; Return true if the string is palindromic ; Function to generate string from characters at odd indices ; Function to generate string from characters at even indices ; Functions to checks if string is Even - Odd Palindrome or not ; Generate odd indexed string ; Generate even indexed string ; Check for Palindrome ; Driver code
function isPalindrome ( str ) { var l = 0 ; var h = str . length - 1 ; while ( h > l ) { if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ; } return true ; } function makeOddString ( str ) { var odd = " " ; for ( var i = 1 ; i < str . length ; i += 2 ) { odd += str . charAt ( i ) ; } return odd ; } function makeevenString ( str ) { var even = " " ; for ( var i = 0 ; i < str . length ; i += 2 ) { even += str . charAt ( i ) ; } return even ; } function checkevenOddPalindrome ( str ) { var odd = makeOddString ( str ) ; var even = makeevenString ( str ) ; if ( isPalindrome ( odd ) && isPalindrome ( even ) ) document . write ( " " ) ; else document . write ( " " ) ; } var str = " " ; checkevenOddPalindrome ( str ) ;