Last active
May 26, 2019 02:33
-
-
Save yixiaoyx/dca24500ef3bd524225dc2e2e387d9c4 to your computer and use it in GitHub Desktop.
A Tour of Go Exercise
This file contains 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
// count occurrences of words in a sentence | |
package main | |
import ( | |
"golang.org/x/tour/wc" | |
"strings" | |
) | |
// my solution here | |
func WordCount(s string) map[string]int { | |
m := make(map[string]int) | |
f := strings.Fields(s) | |
for _, w := range f { | |
m[w] += 1 | |
} | |
return m | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment