CountChars counts the number of a times a character has occurred in the provided string argument and returns a map with `rune` as keys and the count as value.
(text string)
| 10 | // has occurred in the provided string argument and |
| 11 | // returns a map with `rune` as keys and the count as value. |
| 12 | func CountChars(text string) map[rune]int { |
| 13 | charMap := make(map[rune]int, 0) |
| 14 | for _, c := range text { |
| 15 | if _, ok := charMap[c]; !ok { |
| 16 | charMap[c] = 0 |
| 17 | } |
| 18 | charMap[c]++ |
| 19 | } |
| 20 | return charMap |
| 21 | } |
no outgoing calls