Last active
August 29, 2015 14:09
-
-
Save erickhun/25539167b081f206d363 to your computer and use it in GitHub Desktop.
Go Tour Excercice : WordCount with map
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
package main | |
import ( | |
"code.google.com/p/go-tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
map_result := make(map[string]int) | |
splitted := strings.Fields(s) | |
for _, val:= range splitted { | |
map_result[val] = map_result[val] + 1 | |
} | |
return map_result | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment