Skip to content

Create ride-share.rb Katherine#44

Open
KatherineJF wants to merge 1 commit into
Ada-C10:masterfrom
KatherineJF:master
Open

Create ride-share.rb Katherine#44
KatherineJF wants to merge 1 commit into
Ada-C10:masterfrom
KatherineJF:master

Conversation

@KatherineJF

Copy link
Copy Markdown

ride share

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What did your data structure look like at first? Did this structure evolve over time? Why? Yes, I had everything in a hash but I couldn't iterate easily.
What was your strategy for going through the data structure and gathering information? Using .each to fetch key values from the hashes.
What was an example of something that was necessary to store in a variable? What was the scope of each of that variables? Why? the index of the array item with max value
What kinds of iteration did you use? Did you use .map? no, i used .each if I could do it again I would have answered the last two questions using map. I ran out of time to complete my print method at the end
Were some calculations easier than others? Why? The first couple of questions were easier because they didn't involve storing a variable

@CheezItMan

Copy link
Copy Markdown

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.

Comment thread ride-share.rb Katherine
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread ride-share.rb Katherine
[
{ :name =>"driver_one",
id:"dr0001",
date:["3rd Feb 2016", "3rd Feb 2016", "5th Feb 2016"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
      }
    ]
  },
...

Comment thread ride-share.rb Katherine
driver_name = 0

drivers.each do |key, value|
driver_rating = key.fetch(:rating)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why use fetch why not use key[:rating]

Comment thread ride-share.rb Katherine
end
end

driver_rides(drivers,rides)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
end

The same applies to other methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants