Solución
solution.tsTypeScript
function trim(text: string): string {
// Tu código aquí
const words = text.split('');
const specialWords = [' ', '\t', '\n'];
let startIndex = -1;
let endIndex = -1;
for(let i = 0; i < words.length; i++) {
const word = words[i];
if (!specialWords.includes(word)) {
startIndex = i;
break;
}
}
for (let i = words.length - 1; i > 0; i--) {
const word = words[i];
if (!specialWords.includes(word)) {
endIndex = i;
break;
}
}
const finalString: string[] = [];
for (let i = startIndex; i <= endIndex; i++) {
finalString.push(words[i]);
}
return finalString.join('')
}
// No modificar: necesario para evaluar el resultado.
export { trim };0respuestas