Create ride-share.rb Katherine#44
Conversation
|
There are some good things here, but you have some issues and I left some comments in your code. Take a look and let me know if you have questions. |
| money_big << money_b.sum | ||
| money_big_total = money_big.each_with_index.max[1] | ||
| if money_big_total == 0 | ||
| puts "driver_one made the most money" |
There was a problem hiding this comment.
By putting this in the loop you're repeating this statement several times. You've also got other issues with this method as it's just looking at 2 drivers.
| [ | ||
| { :name =>"driver_one", | ||
| id:"dr0001", | ||
| date:["3rd Feb 2016", "3rd Feb 2016", "5th Feb 2016"], |
There was a problem hiding this comment.
This type of 3 parallel arrays for date, cost, rider-id and rating works, but is a little tougher to manager as you have to keep the indexes aligned.
Instead consider:
drivers = [
{
id: 'DR0001",
trips: [
{
date: '3rd Feb 2016',
cost: 10,
rider_id: 'RD0003',
rating: 3
},
{
date: '3rd Feb 2016',
cost: 30,
rider_id: 'RD0015',
rating: 4
},
{
date: '5th Feb 2016',
cost: 45,
rider_id: 'RD0003',
rating: 2
}
]
},
...| driver_name = 0 | ||
|
|
||
| drivers.each do |key, value| | ||
| driver_rating = key.fetch(:rating) |
There was a problem hiding this comment.
why use fetch why not use key[:rating]
| end | ||
| end | ||
|
|
||
| driver_rides(drivers,rides) |
There was a problem hiding this comment.
I suggest not mixing main program code and method definitions it makes things harder to read.
Also rides is 0, and you're just assigning it a value in the method, so you should just make it a local variable instead of a parameter.
def driver_rides(drivers)
ride_total = 0
driver_name = 0
rides = 0
drivers.each do |key, value|
rides = key.fetch(:rider_id)
puts "Key is #{key.class}"
ride_total = rides.count
driver_name = key.fetch(:name)
puts "#{driver_name}" + " "+ "had" + " " + "#{ride_total}" + " " "rides"
end
endThe same applies to other methods
ride share
Congratulations! You're submitting your assignment.
Comprehension Questions
.map?