Length

in #ita2 days ago

export function encode(text:string) {

let res = "";

let num = 1;

for(let i=0; i<text.length; i++){

if(i<text.length - 1 && text[i] === text[i+1]){

  num +=1;

}

else{

      if(num === 1){

        res += text[i];

      }



      else {

      res += (num.toString() + text[i]);

      num = 1;

    }

}

}

return res;

}

export function decode(text:string) {

let res = "";

let tras = "";

let counter = 0;

for(let i=0; i<text.length; i++){

if (/^\d$/.test(text[i])){

  tras += text[i];}

else{

    if(tras !== ""){

      counter = parseInt(tras,10);

      for( let j=0; j< counter-1; j++){

        res += text[i];

      } 

    tras = "";

}

res += text[i];

}

}

return res;

}

Sort:  

Thank you for your witness vote!
Have a !BEER on me!
To Opt-Out of my witness beer program just comment STOP below


Hey @drago18121996, here is a little bit of BEER from @isnochys for you. Enjoy it!

We love your support by voting @detlev.witness on HIVE .