01-01 First Green Test
Why this matters
Text normalization prevents artificial vocabulary inflation from casing and spacing artifacts, so downstream counts represent real language patterns.
Intuition first (no jargon)
Before any model logic, make equivalent text map to the same normalized string.
Code walkthrough
You will implement:
jsexport function normalizeText(text) { // lowercase and trim extra edges }
Your task
Implement normalizeText(text).
- Convert to lowercase.
- Trim spaces at the start and end.
- Collapse internal repeated spaces to one space.
Hints
String(text)helps with unexpected inputs.toLowerCase()handles casing.- A regex like
/\s+/gcan collapse repeated spaces.
Check your thinking
- Why is consistent casing useful for learning patterns?
- What changes if you do not trim text first?
- Should punctuation be removed in this lesson?
Stretch (optional)
Preserve newlines while still collapsing repeated spaces inside each line.
Likely test focus
- Returns lowercase output.
- Removes leading and trailing whitespace.
- Collapses repeated internal spaces.
What should improve
Your preprocessing step now yields stable, repeatable input for counting and modeling.
Bridge to next lesson
Now that text is clean, you can count what the model actually sees.