-
Notifications
You must be signed in to change notification settings - Fork 54
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
Update and rename worksheet.rb to Sophia_worksheet.rb #41
base: master
Are you sure you want to change the base?
Conversation
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.
Overall pretty well done. You hit the main learning goals here.
I do suggest you use methods a bit rather than put everything into the main program. You also struggled with the last two questions to answer. See my inline comments for some ideas. Let me know if you have questions and I'll be happy to answer them.
# rider_data.map do |driver, earnings| | ||
# sum = rider_data[driver].sum do |i| | ||
# i[:cost] | ||
# maximum = sum.max {|i|} | ||
# puts maximum | ||
# end | ||
# puts "#{driver}: has made $#{maximum}." | ||
# end |
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.
You could do something like this. 1st use map
to create an array of hashes with the keys being the driver id and the value being their total earnings.
# rider_data.map do |driver, earnings| | |
# sum = rider_data[driver].sum do |i| | |
# i[:cost] | |
# maximum = sum.max {|i|} | |
# puts maximum | |
# end | |
# puts "#{driver}: has made $#{maximum}." | |
# end | |
rider_earnings = rider_data.map do |driver, earnings| | |
# Total up this driver's earnings | |
total_earnings = earnings.sum do |trip| | |
trip[:cost] | |
end | |
# map this list of drivers into an array of hashes with the | |
# driver ids and their total earnings. | |
{ driver_id: driver, total_earnings: total_earnings} | |
end | |
# find the highest paid entry in that array of hashes. | |
highest_paid_driver = rider_earnings.max_by do |driver_earnings| | |
driver_earnings[:total_earnings] | |
end | |
puts "Highest Paid driver = #{highest_paid_driver}" |
puts "Highest Average Rating:" | ||
puts | ||
|
||
# Which driver has the highest average rating? |
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.
See above you can do something similar here.
Assignment Submission: Ride Share
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection
.map
? If so, when? If not, why, or when would be a good opportunity to use it?