Improved word count
This commit is contained in:
parent
675b497a70
commit
8b525e218e
@ -2,20 +2,19 @@ package main
|
||||
|
||||
import "fmt"
|
||||
import "io"
|
||||
import "io/ioutil"
|
||||
import "log"
|
||||
import "os"
|
||||
import "bufio"
|
||||
import "strings"
|
||||
|
||||
func wc(r io.Reader) map[string]uint {
|
||||
words := make(map[string]uint)
|
||||
if text, err := ioutil.ReadAll(r); err != nil {
|
||||
log.Fatalln(err)
|
||||
} else {
|
||||
for _, word := range strings.Fields(string(text)) {
|
||||
s := bufio.NewScanner(r)
|
||||
s.Split(bufio.ScanWords)
|
||||
for s.Scan() {
|
||||
word := strings.ToLower(s.Text())
|
||||
words[word]++
|
||||
}
|
||||
}
|
||||
return words
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user