Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Ada-C14-Taylor #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions Ada-C14-Taylor
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
rides = [
[
{driver_id: "DR0001",
date: "2/3/16",
cost: 10,
rider_id: "RD0003",
rating: 3},
{driver_id: "DR0001",
date: "2/5/16",
cost: 45,
rider_id: "RD0003",
rating: 2},
{driver_id: "DR0001",
date: "2/3/16",
cost: 30,
rider_id: "RD0015",
rating: 4}
],
[
{driver_id: "DR0002",
date: "2/3/16",
cost: 25,
rider_id: "RD0073",
rating: 5},
{driver_id: "DR0002",
date: "2/4/16",
cost: 15,
rider_id: "RD0013",
rating: 1},
{driver_id: "DR0002",
date: "2/5/16",
cost: 35,
rider_id: "RD0066",
rating: 3}
],
[
{driver_id: "DR0003",
date: "2/4/16",
cost: 5,
rider_id: "RD0066",
rating: 5},
{driver_id: "DR0003",
date: "2/5/16",
cost: 50,
rider_id: "RD0003",
rating: 2}
],
[
{driver_id: "DR0004",
date: "2/5/16",
cost: 20,
rider_id: "RD0073",
rating: 5},
{driver_id: "DR0004",
date: "2/3/16",
cost: 5,
rider_id: "RD0022",
rating: 5},
{driver_id: "DR0004",
date: "2/4/16",
cost: 10,
rider_id: "RD0022",
rating: 4}
]
]

puts "Rides: \n\n"

def how_many_rides(array)
i = 0
array.length.times do
puts "Driver DR000#{i + 1} gave #{array[i].length} rides"
i += 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funky indentation:

Suggested change
i += 1
i += 1

end
end

how_many_rides(rides)

puts "\nEarnings: \n\n"

def how_much_money(array)
i = 0
array.length.times do
if array[i].length == 3
puts "Driver DR000#{i +1} made $#{array[i][0][:cost] + array[i][1][:cost] + array[i][2][:cost]}"
else
puts "Driver DR000#{i + 1} made $#{array[i][0][:cost] + array[i][1][:cost]}"
end
i += 1
Comment on lines +84 to +89

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can clean this up using sum on the inner array:

Suggested change
if array[i].length == 3
puts "Driver DR000#{i +1} made $#{array[i][0][:cost] + array[i][1][:cost] + array[i][2][:cost]}"
else
puts "Driver DR000#{i + 1} made $#{array[i][0][:cost] + array[i][1][:cost]}"
end
i += 1
puts "Driver DR000#{i +1} made $#{array[i].sum {|ride| ride[:cost] }}"
i += 1

end
end

how_much_money(rides)

puts "\nAverage Rating: \n\n"

def avg_rating(array)
i = 0
array.length.times do
if array[i].length == 3
x = (array[i][0][:rating] + array[i][1][:rating] + array[i][2][:rating]) / 3.0

puts "Driver DR000#{i + 1}'s average rating was #{x.round(2)}"
else
x = (array[i][0][:rating] + array[i][1][:rating]) / 2.0
puts "Driver DR000 #{i + 1}'s average rating was #{x.round(2)}"
end
i += 1
end
end

avg_rating(rides)

puts "\nHighest Earnings: \n\n"

def max_money(array)
money = []
i = 0
array.length.times do
if array[i].length == 3
x = array[i][0][:cost] + array[i][1][:cost] + array[i][2][:cost]
money << x
else
x = array[i][0][:cost] + array[i][1][:cost]
money << x
end
i += 1
end
puts "Driver DR000#{money.index(money.max) +1} made the most money with a total of $#{money.max}"
end

max_money(rides)


puts "\nHighest Rating: \n\n"

def max_rating(array)
ratings = []
i = 0
array.length.times do
if array[i].length == 3
x = (array[i][0][:rating] + array[i][1][:rating] + array[i][2][:rating]) / 3.0
ratings << x
else
x = (array[i][0][:rating] + array[i][1][:rating]) / 2.0
ratings << x
end
i += 1
end
puts "Driver DR000#{ratings.index(ratings.max) + 1} had the highest average rating with #{ratings.max.round(2)}"
end

max_rating(rides)