Created
April 9, 2019 22:12
-
-
Save kevin-miles/83d14ec52711b28157cf363bb7cd6afd 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 ( | |
"golang.org/x/tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
elements := strings.Fields(s) | |
elementMap := make(map[string]int) | |
for i := 0; i < len(elements); i++ { | |
elementMap[elements[i]] = elementMap[elements[i]] + 1 | |
} | |
return elementMap | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment