Last active
January 15, 2017 00:09
-
-
Save amstee/8fd6fbbec67366a0ff69aa7d88a8f709 to your computer and use it in GitHub Desktop.
An answer for the exercise maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ( | |
| "strings" | |
| ) | |
| func WordCount(s string) (container map[string]int) { | |
| fields := strings.Fields(s) | |
| container = make(map[string]int) | |
| for i := 0; i < len(fields); i++ { | |
| if _, ok := container[fields[i]]; ok == true { | |
| container[fields[i]] += 1 | |
| } else { | |
| container[fields[i]] = 1 | |
| } | |
| } | |
| return | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment