Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rle_encode(str){
- let i=0, res="";
- while( i<str.length ){
- let oc=1;
- while( i<str.length-1 && str[i]==str[i+1] ){
- i++; oc++;
- }
- res += oc+str[i];
- i++;
- }
- return res;
- }
- function rle_decode(str){
- let i=0, res="";
- while( i<str.length ){
- let nbr=0, k=0;
- while( !isNaN(str[i]) ){
- nbr = 10*nbr+parseInt(str[i]);
- i++;
- }
- while( k<nbr ){
- res += str[i];
- k++;
- }
- i++;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment