text: Print characters and their frequencies in order of occurrence | Javascript implementation to print the characters and frequencies in order of its occurrence ; Store all characters and their frequencies in dictionary ; Print characters and their frequencies in same order of their appearance ; Print only if this character is not printed before ; Driver Code
code: function prCharWithFreq ( s ) { var d = new Map ( ) ; s . split ( ' ' ) . forEach ( element => { if ( d . has ( element ) ) { d . set ( element , d . get ( element ) + 1 ) ; } else d . set ( element , 1 ) ; } ) ; s . split ( ' ' ) . forEach ( element => { if ( d . has ( element ) && d . get ( element ) != 0 ) { document . write ( element + d . get ( element ) + " " ) ; d . set ( element , 0 ) ; } } ) ; } var s = " " ; prCharWithFreq ( s ) ;