Created
September 11, 2014 15:12
-
-
Save oldergod/3a28022ed0f0c7648da0 to your computer and use it in GitHub Desktop.
Tour of Go Maps
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 { | |
array := strings.Fields(s) | |
m := make(map[string]int) | |
for _, word := range array { | |
m[word] = m[word] + 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