Skip to content

Instantly share code, notes, and snippets.

@par6n
Created Jun 6, 2018
Embed
What would you like to do?
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
fields := strings.Fields( s )
output := map[string]int{}
for _,v := range fields {
if _, exists := output[v]; exists {
output[v] = 1
} else {
output[v] += 1
}
}
return output
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment