Update and rename worksheet.rb to Sophia_worksheet.rb#41
Open
SoCodeDo wants to merge 1 commit intoAda-C14:masterfrom
Open
Update and rename worksheet.rb to Sophia_worksheet.rb#41SoCodeDo wants to merge 1 commit intoAda-C14:masterfrom
SoCodeDo wants to merge 1 commit intoAda-C14:masterfrom
Conversation
CheezItMan
reviewed
Sep 14, 2020
Collaborator
CheezItMan
left a comment
There was a problem hiding this comment.
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.
Comment on lines
+148
to
+155
| # 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 |
Collaborator
There was a problem hiding this comment.
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.
Suggested change
| # 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? |
Collaborator
There was a problem hiding this comment.
See above you can do something similar here.
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.
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?