Tanja Stroble -- Carets Ride Share#23
Open
misstonbon wants to merge 2 commits into
Open
Conversation
CheezItMan
reviewed
Aug 15, 2017
CheezItMan
left a comment
Collaborator
There was a problem hiding this comment.
A few comments, a creative approach to organizing the data, but a little difficult to maintain.
| i = 0 | ||
| drivers = [ # drivers array | ||
| #index 0 of drivers array | ||
| driver1 = { |
Collaborator
There was a problem hiding this comment.
You don't need things like this driver1 = { here.
I also think making these internal hashes containing 3 arrays, rather awkward to traverse. It's also problematic if you accidentally add an element to one array and not the others, they become out of synch.
I would suggest instead doing something like:
driver = [
{RD0073: [
{ride_id: "RD0003", rating: 3, pay: 10, dates_active: "2016-02-03"},
{ride_id: "RD0004", rating: 4, pay: 12, dates_active: "2016-02-07"}
]
}
] That makes it easier to loop through things and keeps trips together logically.
| drivers.each do |driver| | ||
| i += 1 | ||
| puts "Driver#{i} pay: $#{driver[:pay].sum} for #{driver[:ride_id].length} rides." #calculating pay and ride number | ||
| puts "Driver#{i}'s average rating is #{(driver[:rating].inject(0.0) { |sum, el| sum + el } / driver[:rating].size).round(2) |
Collaborator
There was a problem hiding this comment.
Nice work using an enumerable (inject) to sum up the pay.
Also good work using round.
Collaborator
|
Feedback provided in code notes |
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.
No description provided.