Solución
solution.tsTypeScript
function compressString(text: string): string {
const newText = []
const textSplit = text.split("")
let count = 1
textSplit.forEach((value, index) => {
let target = value
if (textSplit.at(index + 1) !== target) {
newText.push(`${target}${count}`)
target = value
count = 1
return
}
count += 1
})
return newText.join('')
}
// No modificar: necesario para evaluar el resultado.
export { compressString };0respuestas