Created
February 28, 2020 15:31
-
-
Save Pygmalion69/1dcc28167ba4a4459de66dc7d4d4ff6b 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
// https://tour.golang.org/moretypes/23 | |
package main | |
import ( | |
"strings" | |
"golang.org/x/tour/wc" | |
) | |
func WordCount(s string) map[string]int { | |
m := make(map[string]int) | |
for _, word := range strings.Fields(s) { | |
m[word]++ | |
} | |
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