Write countWords(text): count how often each word appears, using a Map.
countWords(text) returns a Map from each word in text, in lowercase, to the number of times it appears. The words are in the order they first appear.
Ignore case, so The and the are the same word. Punctuation isn't part of a word, except an apostrophe inside one, as in don't. Letters with accents, as in café, count as letters.
function countWords(text) {
// your code
}
// countWords("The cat and the hat.");
// Map(4) {"the" => 2, "cat" => 1, "and" => 1, "hat" => 1}
// countWords("Don't stop. Café, café!");
// Map(3) {"don't" => 1, "stop" => 1, "café" => 2}
The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…