Word Frequency Counter
Text analysis shows up everywhere: search engines, recommendation systems, spam filters.
This project teaches you:
- String manipulation
- Hash maps (objects / Maps) for counting
- Sorting by value
- Text normalization
The Spec
Build a WordFrequency class that:
analyze(text)— process a string of textgetTopN(n)— return the top N most frequent words as[{word, count}]getCount(word)— return how many times a word appearsgetUnique()— return how many unique words exist
Rules:
- Case-insensitive ("The" and "the" are the same)
- Strip punctuation (commas, periods, etc.)
- Ignore empty strings after cleaning
Real-World Applications
- SEO tools — what words appear most on a page?
- Chatbots — what topics do users ask about?
- Spam detection — "free", "win", "click" patterns
⚡ 50 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
counts words
case insensitive
getTopN returns sorted
getUnique counts distinct words
Run your code to check these.