Word Frequency Counter
Given a string of words, count how many times each word appears. Return the counts as an object where the keys are words and the values are the counts of those words. Words should be considered the same regardless of case (treat 'Dog' and 'dog' as the same word).
Explanation. Both 'Hello' and 'world' occur twice, ignoring the case and punctuation.
Explanation. Counts all the words, treating 'It's' the same as "it's".
Explanation. Treats all 'one' words the same, ignoring case and removing punctuation.
Follow-up: How would you modify your solution if you needed to include certain punctuations as part of words, such as hyphens in double-barreled names or apostrophes in contractions?
Input string may contain punctuation which should not be considered part of the words. Words are split by spaces. Assume input string is not `null` or empty.
- Views
- 2