Counting occurrences of s [ 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 ( " " ) ; }