Intermediate
Word counts with a Map
Write countWords(text) that returns a Map from each word (lower-case, without punctuation) to how many times it appears, in the order words first appear.
Write topWords(text, n) that returns the n most common words as [word, count] pairs, most common first; words with equal counts keep their first-appearance order.
When the Count button is clicked, show the top 3 words from the textarea in #top, one <li> each, written like red: 3.
What Check tests
countWordsreturns a Map of counts- Punctuation and capitals are ignored
topWordsreturns the most common pairs first- Ties keep first-appearance order
- Clicking Count shows the top 3
- No errors
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.