输入一串字符,请编写一个字符串压缩程序,将字符串中连续出现的重复字母进行压缩,并输出压缩后的字符串。 例如: aac 压缩为 1ac xxxxyyyyyyzbbb 压缩为 3x5yz2b
while(line = readline()) { let input = line; let outArr = []; let count = 0; for (let i = 0; i < input.length; i++) { if (input[i] === input[i + 1]) { count ++; } else { if(count !== 0){ outArr.push(count); }; outArr.push(input[i]); count = 0; }; }; console.log(outArr.join('')); };