Skip to content

Sockets - Jansen#45

Open
JansenMartin wants to merge 1 commit intoAda-C11:masterfrom
JansenMartin:master
Open

Sockets - Jansen#45
JansenMartin wants to merge 1 commit intoAda-C11:masterfrom
JansenMartin:master

Conversation

@JansenMartin
Copy link

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? At first, I wanted to organize it as an array of hashes, with each hash representing a trip. However, I looked at the questions (which are very driver-centric). Then, I made the outer layer an array of hashes -- with each hash representing a driver. Then, in each driver hash, I added an array of trip hashes.
What was your strategy for going through the data structure and gathering information? I would make sure I could access a simpler version of the data structure (for example, an array inside a hash). Then, I gradually made the loop more complex as I added more outer layers.
What was an example of something that was necessary to store in a variable? Why was it necessary, useful, or helpful? I noticed I have a tendency to avoid using temporary hashes. However, in the optional enhancement, it was helpful to temporarily store each driver's trip dates and trip costs separately. This made it easier to identify whether multiple days tied as the most lucrative for that driver.
What kinds of iteration did you use? Did you use .map? If so, when? If not, why, or when would be a good opportunity to use it? I used .map when creating new arrays for ratings and trip costs. These were stored inside .each loops.
Were some calculations easier than others? Why? The optional calculation was the most difficult. This is because we're working with the same few dates across multiple drivers. When making a temporary hash, the hash keys can easily overwrite one another if you don't use conditionals.

@JansenMartin JansenMartin changed the title Rename worksheet.rb to ride-share.rb Sockets - Jansen Feb 19, 2019
@droberts-sea
Copy link

Ride Share

What We're Looking For

Feature Feedback
Answers the comprehension questions yes
Readable code with consistent indentation and reasonable code style yes
Outputs the correct number of rides each driver has given yes
Outputs the total amount of money each driver has made yes
Outputs the average rating for each driver yes
Outputs which driver made the most money yes
Outputs which driver has the highest average rating yes

Great job overall! I've left a couple of comments inline, but it's clear that the learning goals for this assignment around working with loops and complex data structures were met. Keep up the hard work!

drivers = [
{id: "DR0004", trips: [ # driver
{date: "3rd Feb 2016", cost: 5, rider_id: "RD0022", rating: 5}, #trip
{date: "4th Feb 2016", cost: 10, rider_id: "RD0022", rating: 4}, # trip

Choose a reason for hiding this comment

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

While I like the idea of this data structure, I might space it out in the file a little differently. In general, best practice is that unless the entire array or hash is going on one line, each key/value pair should get its own line. So in this case:

drivers = [
  {
    id: "DR004",
    trips: [
      {date: "3rd Feb 2016", cost: 5, rider_id: "RD0022", rating: 5}, #trip
      {date: "4th Feb 2016", cost: 10, rider_id: "RD0022", rating: 4}, # trip
    ]
  }, {
    ... next driver
  }
}

puts "\nCongratulations, #{highest_earning_driver}! You earned the most money."

# Which driver has the highest average rating?
highest_rated_driver = drivers.max_by { |driver| driver[:average_rating] }[:id]

Choose a reason for hiding this comment

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

I would probably break lines 51 and 55 out across multiple lines using do...end rather than curly braces. If you're worried about the subscript (the [:id]) at the end, you could stick that inside the string interpolation.

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