Laura_ride-share.rb#32
Conversation
|
Your data structure works although it can be a bit awkward to keep rating, date, rider and cost all aligned with the same index. You've got some good helper methods and you did a good job checking to see if a driver had multiple trips on one day. Really nice work! You hit all the learning goals. |
| { | ||
| :driver_id => "DR0001", | ||
| :rating => [3,4,2], | ||
| :rider_id => ["RD0003","RD0015","RD0003"], |
There was a problem hiding this comment.
You're using parallel arrays here, which is fine, but it can be awkward to keep them aligned. It would be easier to have one array of trips with date, rider_id, rating, and cost keys.
| def add_values_hash(hash) | ||
| newhash = Hash.new() | ||
| hash.each do |k, v| | ||
| newhash[k] = v.reduce(:+) |
There was a problem hiding this comment.
So this will replace the array of values with the sum, eliminating the original data.
| totals_rating << driver[:average_rating] | ||
|
|
||
| # calculate the date in which the highest money was made | ||
| if driver[:dates].uniq.length == driver[:dates].length # one trip per day |
There was a problem hiding this comment.
I would think about drying this out so you could have one block of code that would calculate the max money on each date regardless if they had 1 trip or multiple.
| hash = Hash.new() | ||
| dates.each_with_index do |date, index| | ||
| # if key is not present in the hash, create it with an array as the value | ||
| hash[date] ||= [] # hash[key] = hash[key] || [] |
There was a problem hiding this comment.
There's also a group_by Enumerable which could be helpful.
ride share
Congratulations! You're submitting your assignment.
Comprehension Questions
.map?