Skip to content

Instantly share code, notes, and snippets.

@philiplambok
Created September 18, 2022 06:52
Show Gist options
  • Save philiplambok/7247fb43694d8e8015d2484f9faef184 to your computer and use it in GitHub Desktop.
Save philiplambok/7247fb43694d8e8015d2484f9faef184 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 {
words := strings.Split(s, " ")
var count int
word_maps := make(map[string]int)
for _, word := range words{
el, ok := word_maps[word]
if(ok) {
count = el + 1
} else {
count = 1
}
word_maps[word] = count
}
return word_maps
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment