Conversation
Ride ShareWhat We're Looking For
Hi Amy! Great job on this project. Your code style is great and your strategies were what I was looking for! Great job on getting all of the iteration, and using methods from I'd like to give some very vague questions as "food for thought" (I know that we don't want to ever leave you with vague questions, but I'm going to allow ourselves to do this for this project):
That being said, you did great on this project and calculated everything correctly and got all of the correct answers. Well done! |
| puts "Total number of rides for each driver:" | ||
| i = 0 | ||
| rideshare_info.each do |driver| | ||
| puts "Driver #{(driver[:driver])[-1]}: #{number_of_rides[i]}" |
There was a problem hiding this comment.
I like the care and effort you put into making this output more readable to humans :) You could have just printed id but instead you put in work to give it a nice number. I want to be clear that this wasn't a requirement, but it sure was nice! :D
|
|
||
| puts "Total number of rides for each driver:" | ||
| i = 0 | ||
| rideshare_info.each do |driver| |
There was a problem hiding this comment.
In order to keep track of the index so you could use it to index into another array, you made an i variable. You probably will be happy to know that something exists for you to use in the future: each_with_index. This gives you a reference to a second iteration variable besides driver, and you use it like this:
number_of_rides = driver_rides(rideshare_info)
puts "Total number of rides for each driver:"
rideshare_info.each do |driver, i|
puts "Driver #{(driver[:driver])[-1]}: #{number_of_rides[i]}"
end|
|
||
| def driver_pay(info) | ||
| paychecks = info.map do |driver| | ||
| (driver[:cost]).reduce(:+) |
There was a problem hiding this comment.
(driver[:cost]).reduce(:+) is the same as (driver[:cost]).sum, in case you wanted even another approach to this
| paycheck = info.map do |driver| | ||
| [(driver[:cost]).reduce(:+), driver[:driver]] | ||
| end | ||
| most_cash = paycheck.max |
There was a problem hiding this comment.
Nice 👍 I like this line, and this method in general :D
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?