Run Length Encoding | Javascript program to implement run length encoding ; Count occurrences of current character ; Print character and its count ; Driver code
function printRLE ( str ) { let n = str . length ; for ( let i = 0 ; i < n ; i ++ ) { let count = 1 ; while ( i < n - 1 && str [ i ] == str [ i + 1 ] ) { count ++ ; i ++ ; } document . write ( str [ i ] ) ; document . write ( count ) ; } } let str = " " ; printRLE ( str ) ;