-
Notifications
You must be signed in to change notification settings - Fork 25
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
Panda, Tiger, and Eagle code. #20
base: master
Are you sure you want to change the base?
Conversation
dictionary | ||
end | ||
|
||
def separate_by_years |
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 feel like with all of the wiz-bang stuff in Ruby "decompose this array into multiple sub arrays based on a block's evaluation" should be easier, but I couldn't find out to do it without the recursion in separate_by_years
and array_of_years
. Any suggestions?
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 one of the reasons you're having trouble is that array feels too difficult here. I think hash is the appropriate data type here.
def movies_by_year(movies)
hash = {}
movies.each do |movie|
hash[movie.year] ||= []
hash[movie.year] << movie
end
hash
end
ok, so now you have a hash by year, which is easier to deal with.
In ruby, the data-type most often reached for is the hash. arrays are generally pretty stupid and simple lists.
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.
Duh. That makes a lot more sense. Let me refactor this stuff and let you take another look. Thanks.
Looks entirely technically correct, good job! Do you want to re-work the Collection class with the hash? otherwise, here are some style notes:
|
With the Tiger discussion, I couldn't tell whether you really wanted the "average year" or the "average in a year", so I did both. :-)
There's a couple of spots I have comments/questions about that I'll add inline.