What you're building
A wordRank(text) function that takes a plain-text string and returns an array of
{ word, count } objects sorted from most-frequent to least-frequent.
Requirements
- Convert the input to lowercase before counting.
- Strip all non-alphabetic characters (punctuation, numbers) so
"don't"becomes"dont". - Ignore empty strings produced by splitting.
- Return an array of
{ word: string, count: number }objects. - Sort descending by count; ties may appear in any order.
Stretch goals
- Accept a second argument
nand return only the top-N words. - Treat a configurable list of stop-words (the, a, an, is…) as invisible.
What this proves
You can normalize messy real-world text, aggregate with a hash map, and sort by value — three skills that appear in data engineering, NLP pipelines, and technical interviews.
⚡ 40 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
returns ranked array
case insensitive
strips punctuation
empty string returns empty array
Run your code to check these.