Solución
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