-
-
Save 345161974/d3cc14856012dab870a80c67bdc8629f to your computer and use it in GitHub Desktop.
An answer of the exercise: Maps on a tour of Go
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
package main | |
import ( | |
"code.google.com/p/go-tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
m := make(map[string]int) | |
a := strings.Fields(s) | |
for _, v := range a { | |
m[v]++ | |
} | |
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