Printing frequency of each character just after its consecutive occurrences | Javascript program to print run length encoding of a string ; Counting occurrences of s [ i ] ; Driver code
function printRLE ( s ) { for ( var i = 0 ; i < s . length ; i ++ ) { var count = 1 ; while ( i + 1 < s . length && s . charAt ( i ) == s . charAt ( i + 1 ) ) { i ++ ; count ++ ; } document . write ( s . charAt ( i ) + " " + count + " " ) ; } document . write ( " " ) ; } printRLE ( " " ) ; printRLE ( " " ) ;