A word frequency map shows how many times each distinct word appears in a body of text. It is the foundation of keyword-density checks, basic text analytics, and quick readability or repetition audits.
How it works
The text is tokenised by splitting on whitespace, then each token is normalised and tallied in a map:
tokens = text.split(/\s+/) // split on whitespace
for each token:
if stripPunctuation: trim leading/trailing symbols
if caseInsensitive: token = token.toLowerCase()
counts[token] += 1
sort rows by count desc, then word asc
Using a map keyed by the normalised word gives an exact count in a single pass. The final sort puts the most common words on top, with alphabetical ordering breaking ties so the table is deterministic.
Worked example
For the input the cat sat on the mat the cat ran:
| Word | Count |
|---|---|
| the | 3 |
| cat | 2 |
| mat | 1 |
| on | 1 |
| ran | 1 |
| sat | 1 |
the tops the list at 3, cat follows at 2. With punctuation stripping on,
dog. and dog would both appear as dog, merged into a single row.
Practical uses
Keyword density for SEO: Divide a word’s count by the total-word count displayed above the table to get a rough density percentage. A term appearing 8 times in a 400-word page sits at 2% density — within the range where it signals topic relevance without triggering over-optimisation.
Repetition audit: Writers use frequency tables to spot over-used words. A word appearing far more often than its peers may read as repetitive; the table surfaces these immediately so you can vary your vocabulary.
Finding filler words: Paste a draft and look at what sits in the 3–10 frequency range. In persuasive writing, words like very, just, really, and actually often cluster there — candidates for removal.
Academic text analysis: Frequency tables are the starting point for stylistic comparison, plagiarism detection research, and basic corpus linguistics. Paste two texts separately, compare the top-10 frequency lists, and common authorial habits become visible.
Choosing the options
Case-insensitive: With this on, The, the, and THE merge into one row.
Turn it off only if capitalisation carries meaning — for example when analysing
code where String and string are different types.
Strip punctuation: With this on, cat, and cat. both count as cat. Leave
it off if punctuation is load-bearing, such as when analysing source code or
structured markup.