Skip to content

Instantly share code, notes, and snippets.

@vishuvenu
Created August 15, 2021 16:28
Show Gist options
  • Save vishuvenu/42aee60e2162b0630305039168d9da39 to your computer and use it in GitHub Desktop.
Save vishuvenu/42aee60e2162b0630305039168d9da39 to your computer and use it in GitHub Desktop.
WordCount.go
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
wc := make(map[string]int)
for _, word := range strings.Split(s, " ") {
if _, exist := wc[word]; !exist {
wc[word] = 0
}
wc[word] += 1
}
return wc
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment