-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EX 01 #150
base: master
Are you sure you want to change the base?
EX 01 #150
Conversation
) | ||
|
||
func main() { | ||
filename := os.Args[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to handle the scenario when no args or more args are provided before accessing the file name
exercise-001-corpus/word_count.go
Outdated
|
||
func main() { | ||
filename := os.Args[1] | ||
data, err := ioutil.ReadFile(string(filename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.Args
is of type []string
no need of an explicit cast here
exercise-001-corpus/corpus/corpus.go
Outdated
|
||
// Analyze takes in a string of words and returns a slice sorted in reverse numerical order based on the word count | ||
func Analyze(data string) []WordCount { | ||
words := splitWord(string(data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont need the string(data) case here as well.. data is already a string
func (a ByCount) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | ||
|
||
func splitWord(word string) []string { | ||
slice := regexp.MustCompile("[^a-zA-Z0-9']+").Split(word, -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice use of regexp and split
wordSlice := make([]WordCount, 0) | ||
|
||
for index, word := range words { | ||
words[index] = strings.ToLower(word) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just iterate over words and increment count in your map
for _, word := range words {
wordMap[word]++
}
the zero value of ints is 0 in go so it should just work out fine
No description provided.