Count the words
Count how often each word appears in a sentence, using a Map.
intermediateJavaScript
The task
Write a function countWords(text) that returns a Map from each word to how many times it appears.
Then print every word and its count, in the order the words first appear, like the: 3.
Your output should be:
the: 3 cat: 1 and: 2 hat: 1 bat: 1