Skip to content
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

Completed CountingWords #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cmwchoi
Copy link

@cmwchoi cmwchoi commented Jan 13, 2016

@jaybobo @sampriddy @sjreich @paradime Feel like this could be shortened... Thanks!

def generate_sorted_word_hash
unsorted = Hash.new(0)
words = generate_word_array
words.each { |word| unsorted[word] += 1 }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could actually cut out a middle-man here; you define a variable words = generate_word_array and then enumerate over it, when you could just use generate_word_array.each .... If you feel that having the words variable defined increases clarity, though, it might be worth keeping it.

You could also think of using Object#tap and basically wrapping up this entire method body in a block that ultimately returns out the sorted word list. Docs

But really this is fine and nothing needs to be done. Just bringing these up since you were interested in shortening it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants