Conversation
Ride ShareWhat We're Looking For
Good job overall! While there are certainly some things that could be cleaned up, your code works well 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! |
| } | ||
| # count each driver's rides | ||
| rideshare.each {|key, value| puts "Driver #{key} went on a total of #{value.count} rides."} | ||
|
|
There was a problem hiding this comment.
Two comments here:
- I would probably break this out across multiple lines and use
do..endinstead of curly braces keyandvalueare not very descriptive variable names. What aboutdriver_idandrides?
| highest_income = rideshare.map do |key, value| | ||
| { name: key, total: value.sum do |record| | ||
| record[:cost] | ||
| end } |
There was a problem hiding this comment.
Your code structure here is a little odd. It looks like the combination of do..end and hash curly braces made VS Code confused about indentation (it's confusing to me as well). We could rewrite it a little more clearly as:
income_by_driver = rideshare.map do |driver_id, rides|
income = rides.sum do |ride|
ride[:cost]
end
{ name: driver_id, total: income }
endThere was a problem hiding this comment.
Note also the modified variable names 😉
| rideshare.each do |key, value| | ||
| avg_rating = value.sum do |record| | ||
| ((record[:rating].to_f) / value.length).round(2) | ||
| end |
There was a problem hiding this comment.
I notice that you used integer division for the average rating, and lost a little precision.
ride share
Congratulations! You're submitting your assignment.
Comprehension Questions
.map? If so, when? If not, why, or when would be a good opportunity to use it?