Improve wordcount (punctuation, results)

This commit is contained in:
Meutel 2017-07-07 16:29:25 +02:00
parent 8b525e218e
commit c1f98eb796

View File

@ -12,7 +12,11 @@ func wc(r io.Reader) map[string]uint {
s := bufio.NewScanner(r)
s.Split(bufio.ScanWords)
for s.Scan() {
word := strings.ToLower(s.Text())
word := s.Text()
word = strings.ToLower(word)
word = strings.Replace(word, ".", "", -1)
word = strings.Replace(word, ",", "", -1)
word = strings.Replace(word, "\"", "", -1)
words[word]++
}
return words
@ -30,5 +34,13 @@ func main() {
log.Fatalln("Missing file")
}
f := openFile(&os.Args[1])
fmt.Println(wc(f))
words := wc(f)
if len(os.Args) > 2 {
for i := 2; i < len(os.Args); i++ {
word := strings.ToLower(os.Args[i])
fmt.Println(word, words[word])
}
} else {
fmt.Println(words)
}
}