Decode a given string by removing duplicate occurrences | Function to count the appearances of each character ; If the character is lower case ; If the character is uppercase ; If the character is a punctuation mark ; Function to decode the given encoded string ; Iterate the given string str ; Find the index of the next character to be printed ; Driver Code
function findRepitition ( a ) { if ( a . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) && a . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) ) { return a . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } else if ( a <= ' ' && a >= ' ' ) { return a . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } return 0 ; } function decodeString ( str ) { let output = " " ; for ( let i = 0 ; i < str . length ; i ++ ) { output += ( str [ i ] ) ; i += findRepitition ( str [ i ] ) ; } document . write ( " " + output + " " + " " ) ; } let str = " " ; decodeString ( str ) ;