-
Notifications
You must be signed in to change notification settings - Fork 36
Add solution #33
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
base: master
Are you sure you want to change the base?
Add solution #33
Conversation
…moving them). Updating test arrays. Implementing count_from_file method instead of loading file in test directly.
| list[word] += 1 | ||
| else | ||
| list[word] = 1 | ||
| end |
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 can definitely get this done in a single line. Look into other ways of using .each.
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.
Ah. I'm guessing ruby supports assignment if a key doesn't exist? E.g.
words.each do |word|
list[word] += 1
endAlso, I'm not sure what you mean about looking into other ways of using .each. Any suggestions on what to look for?
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.
Check the Ruby documentation for the Each. Should be a big hint as to how you can get that down to a single line. Your eg code is pretty close, but you can totally get it down to just one line. 😃
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.
Oh. You mean by using a single line block?
words.each { |word| list[word] += 1 }
No description provided.