I tried this approach but I was not getting the first element of the string. I tried to convert in the opposite way which was way too easy. But in this one somehow I am missing something. Question is, we need to decipher a string from "aabbcdd" to "a2 b2c1d2"
function check(len, string){
// var obj = {};
var new_string = "";
var count =1;
//console.log(string);
for(var i=0; i < string.length; i++){
let str = string[i];
if(string[i]===string[i+1] ){
count++;
new_string = new_string + string[i+1] + count;
}
if(string[i]!== string[i-1] && string[i]!== string[i+1] && string[i-1] !==undefined){
count = 1;
new_string = new_string + string[i-1] + count;
}
// console.log(string[i],string[i+1], count)
}
console.log(new_string);
}
Thank you