Word frequency
MediumHash maps · JavaScript
The task
Write wordFrequency(text) that returns an object mapping each word to the number of times it appears.
Ignore case and punctuation: split the text into words made of letters and digits, and use the lower-case form of each word. An empty text returns an empty object.
Examples
- wordFrequency("the cat and The dog") returns { the: 2, cat: 1, and: 1, dog: 1 }
Your code runs in your browser, in a separate worker, and is never sent to us. Edit the function, then press Run tests. Your work is saved here as you type.
JavaScriptCtrl or Cmd + Enter to run