Conversation
Ride ShareWhat We're Looking For
Hi Vi! I am REALLY excited and impressed and happy with this project submission! The code is extremely clear, readable, concise, clever, logical, and accurate. Well done! I have a few comments on code style, but overall, I see some great code here. Well done! |
| @@ -0,0 +1,104 @@ | |||
| ######################################################## | |||
There was a problem hiding this comment.
Now that we're working in git, we'll have better ways to upload files, but I wanna point out that you named this file after your PR, which is nice, but I wanted this as worksheet.rb instead of branches- vi rideshare :)
|
|
||
| #Loop inside the drivers hash | ||
| #List each key along with the # of elements in its associated array. | ||
| drivers.each do |driverName, rides| |
There was a problem hiding this comment.
These variable names prove to me that you know the structure of your data deeply. Nice work!
|
|
||
| #Loop inside the drivers hash | ||
| #List each key along with the # of elements in its associated array. | ||
| drivers.each do |driverName, rides| |
There was a problem hiding this comment.
In Ruby, we tend to name variables using snake_case, meaning instead of driverName I may see driver_name instead
|
|
||
| #Loop inside drivers hash | ||
| drivers.each do |driverName, trips| | ||
| total = trips.inject(0) { |sum, trip| sum + trip[:cost].to_i} |
| #3. The average rating for each driver | ||
|
|
||
| drivers.each do |driverName, trips| | ||
| avg_rating = trips.inject(0) { |sum, trip| sum + trip[:rating].to_i } / trips.size |
There was a problem hiding this comment.
It would probably be a more accurate calculation if we did trip[:rating].to_f instead of to_i
| rating_winner_driver = "" | ||
|
|
||
| drivers.each do |driverName, trips| | ||
| avg_rating = trips.inject(0) { |sum, trip| sum + trip[:rating].to_i } / trips.size |
There was a problem hiding this comment.
You end up having this line that calculates average rating based off of an array called trips duplicated. If you had more time to refactor, I may suggest pulling it into a new method. Imagine a method like this:
def calculate_avg_rating(trips)
return trips.inject(0) { |sum, trip| sum + trip[:rating].to_i } / trips.size
endTherefore, this line may be changed to this:
avg_rating = calculate_avg_rating(trips)
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?