Solución

@duron03·7/7/2026TypeScript
solution.tsTypeScript
function countWordsByLength(sentence: string, length: number): number {
  const tokenizedSentence: string[] = tokenizeWords(sentence);
  let count: number = 0;
  tokenizedSentence.forEach(word => {
    if (word.length === length) count++;
  });
  return count;
}

function tokenizeWords(str: string): string[] {
  const wordToIterate: string = str + " ";
  let listOfWords: string[] = [];
  let actualWord: string = "";
  for (let i: number = 0; i < wordToIterate.length; i++) {
    if (wordToIterate[i] === " ") {
      listOfWords.push(actualWord);
      actualWord = "";
    }
    else actualWord += wordToIterate[i];
  }
  return listOfWords;
}

// No modificar: necesario para evaluar el resultado.
export { countWordsByLength };
0respuestas
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.