mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-30 16:01:14 -04:00
fix(curriculum): replacing regex with loop in "Build a Sentence Analyzer" step 8 (#65056)
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user