Open
Conversation
Ride ShareWhat We're Looking For
Great job overall! Your code works well and is generally easy to read, and it is clear to me that the learning goals around working with enumerables and complex data structures were met. Keep up the hard work! |
| def added_ride_info(mama_hash, key) | ||
| new_hash = {} | ||
| mama_hash.each do |driver, rides| | ||
| total = rides.sum { |ride| ride[key] } |
There was a problem hiding this comment.
I love the idea of breaking this functionality out into a separate method, especially the idea of making it more abstract by passing in the field you're interested in summing. However, your names could be a little more descriptive. How about this:
def sum_field_by_driver(rides_by_driver, key)
driver_sums = {}
rides_by_driver.each do |driver_id, rides|
total = rides.sum { |ride| ride[key] }
driver_sums[driver_id] = total
end
return driver_sums
end
Author
There was a problem hiding this comment.
Thank you for the feedback! I agree that using more descriptive names improves the readability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ride share
Congratulations! You're submitting your assignment.
Comprehension Questions
max_bymethod on the hash containing all drivers' total earnings, and the highest earning driver was stored in a variable to make it more convenient to print..map? If so, when? If not, why, or when would be a good opportunity to use it?.eachiterations to gather the data, and used.max_byfor determining the highest rated and highest earning driver. I did use.map, to output ride count, but now I realize it was unnecessary (and I will probably change it after I submit this :)) as it returns a new array. I didn't use.mapbecause my data structure and the ability to access that data is so heavily reliant on keys/values, I didn't see it necessary to add arrays using.map.