Skip to content

Instantly share code, notes, and snippets.

@tossmilestone
Created June 30, 2017 09:04
Show Gist options
  • Save tossmilestone/0d88be02be6d1d5ecf1b80861483380d to your computer and use it in GitHub Desktop.
Save tossmilestone/0d88be02be6d1d5ecf1b80861483380d to your computer and use it in GitHub Desktop.
Words count in go tour
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counts := make(map[string]int)
for _, w := range words {
_, ok := counts[w]
if ok {
counts[w] += 1
} else {
counts[w] = 1
}
}
return counts
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment