Created
October 2, 2017 05:29
-
-
Save meltedice/1cc35996c849a44347efd2deec95605c to your computer and use it in GitHub Desktop.
A Tour of Go: Exercise: 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 ( | |
"strings" | |
"golang.org/x/tour/wc" | |
) | |
func WordCount(s string) map[string]int { | |
wordCount := make(map[string]int) | |
for _, word := range strings.Fields(s) { | |
wordCount[word] += 1 | |
} | |
return wordCount | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment