Traverse through string characters and count frequencies
for ( let i = 0 ; i < str . length ; i ++ ) count [ str [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i <= limit ; i ++ ) { if ( count [ i ] > 0 ) document . write ( String . fromCharCode ( i ) + " " + count [ i ] + " " ) ; } }