Created
February 12, 2015 02:26
-
-
Save waddles/1a9c09d904f74d946208 to your computer and use it in GitHub Desktop.
Go Tour Exercise on Maps - http://tour.golang.org/moretypes/19
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) | |
words := strings.Fields(s) | |
for _,val := range words { | |
m[val] += 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