Solución
solution.tsTypeScript
function compressString(text: string): string {
let c = 1
let s = ""
let l = text[0]
for (let i = 1; i < text.length; i++) {
const r = text[i]
if (l == r) {
c += 1
}
if (l !== r) {
s += `${l}${c}`
c = 1
l = text[i]
}
}
s += `${l}${c}`
return s;
}
// No modificar: necesario para evaluar el resultado.
export { compressString };1respuestas