Case-Insensitive Word Count
Problem statement
Count the occurrences of each word in a text.
For this exercise, assume ASCII input. A word is a maximal consecutive run of English letters A-Z or a-z; every other character is a separator. Compare words case-insensitively and return lowercase words.
For this exercise, assume results follow the order of each word's first appearance. Represent each entry as word:count. Empty input or input with no words returns an empty list.
Function
wordFrequencies(text: String) → String[]Examples
Example 1
text = "Hello world, HELLO!"return = ["hello:2","world:1"]Matching ignores letter case; hello first appears before world.
Example 2
text = "red-blue red2green"return = ["red:2","blue:1","green:1"]Hyphens and digits separate letter runs.
Example 3
text = ""return = []There are no words.
Constraints
- For this exercise, assume
0 <= text.length <= 10^4, with ASCII characters only.