package main
import (
"golang.org/x/tour/wc"
)
func WordCount(s string) map[string]int {
words := make(map[string]int)
var wordstorage string
for i:=0; i < len(s); i++ {
if s[i:i+1] == " " {
words[wordstorage] += 1
wordstorage = ""
} else {
wordstorage += s[i:i+1]
}
}
words[wordstorage] += 1
return words
}
func main() {
wc.Test(WordCount)
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme