fix(curriculum): replacing regex with loop in "Build a Sentence Analyzer" step 8 (#65056)

This commit is contained in:
Valérie
2026-01-12 15:15:44 +01:00
committed by GitHub
parent b2ddf571b8
commit 6df66051dd

View File

@@ -88,8 +88,16 @@ function getWordCount(sentence) {
return 0;
}
const words = sentence.trim().split(/\s+/);
return words.length;
const words = sentence.trim().split(' ');
let count = 0;
for (const word of words) {
if (word !== '') {
count++;
}
}
return count;
}
--fcc-editable-region--
@@ -150,8 +158,16 @@ function getWordCount(sentence) {
return 0;
}
const words = sentence.trim().split(/\s+/);
return words.length;
const words = sentence.trim().split(' ');
let count = 0;
for (const word of words) {
if (word !== '') {
count++;
}
}
return count;
}
const wordCount = getWordCount("I love freeCodeCamp");