Check if string is palindrome after removing all consecutive duplicates | Function to check if a String is palindrome or not ; Length of the String ; Check if its a palindrome ; If the palindromic condition is not met ; Return true as str is palindromic ; Function to check if String str is palindromic after removing every consecutive characters from the str ; Length of the String str ; Create an empty compressed String ; The first character will always be included in the readonly String ; Check all the characters of the String ; If the current character is not same as its previous one , then insert it in the readonly String ; Check if the compressed String is a palindrome ; Given String ; Function call
function isPalindrome ( str ) { let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { if ( str [ i ] != str [ len - i - 1 ] ) return false ; } return true ; } function isCompressablePalindrome ( str ) { let len = str . length ; let compressed = " " ; compressed = str [ 0 ] ; for ( let i = 1 ; i < len ; i ++ ) { if ( str [ i ] != str [ i - 1 ] ) compressed += str [ i ] ; } return isPalindrome ( compressed ) ; } let str = " " ; if ( isCompressablePalindrome ( str ) ) document . write ( " " + " " ) ; else document . write ( " " ) ;