Skip to content

Instantly share code, notes, and snippets.

@par6n
Created June 6, 2018 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save par6n/9f6905c2212364e633c8efcfa4a5f7ec to your computer and use it in GitHub Desktop.
Save par6n/9f6905c2212364e633c8efcfa4a5f7ec to your computer and use it in GitHub Desktop.
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