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

Sockets - Amy #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Sockets - Amy #32

wants to merge 3 commits into from

Conversation

aphunk
Copy link

@aphunk aphunk commented Feb 19, 2019

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? Initially, I had a large array of hashes containing info for each ride, including the driver. After writing code to separate rides by driver, I decided to instead create a hash with drivers as keys and an array of hashes containing individual rides. Because all the questions pertained to the drivers, it was important to call on data by their association with a driver.
What was your strategy for going through the data structure and gathering information? I gathered information using various loops to iterate over the data. Because the ride data was nested inside a driver array, I nested loops to access that info. I stored earnings and ratings information in a hash, knowing that I would need to compare those values later. For the driver count, I simply used a loop to output the values.
What was an example of something that was necessary to store in a variable? Why was it necessary, useful, or helpful? I used the max_by method on the hash containing all drivers' total earnings, and the highest earning driver was stored in a variable to make it more convenient to print.
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 a mostly .each iterations to gather the data, and used .max_by for determining the highest rated and highest earning driver. I did use .map, to output ride count, but now I realize it was unnecessary (and I will probably change it after I submit this :)) as it returns a new array. I didn't use .map because my data structure and the ability to access that data is so heavily reliant on keys/values, I didn't see it necessary to add arrays using .map .
Were some calculations easier than others? Why? Yes! It was much easier to calculate total ratings and earnings because those were simple binary operations. An additional step of dividing was necessary to retrieve the average rating.

@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! Your code works well and is generally easy to read, and it is clear to me that the learning goals around working with enumerables and complex data structures were met. Keep up the hard work!

def added_ride_info(mama_hash, key)
new_hash = {}
mama_hash.each do |driver, rides|
total = rides.sum { |ride| ride[key] }

Choose a reason for hiding this comment

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

I love the idea of breaking this functionality out into a separate method, especially the idea of making it more abstract by passing in the field you're interested in summing. However, your names could be a little more descriptive. How about this:

def sum_field_by_driver(rides_by_driver, key)
  driver_sums = {}
  rides_by_driver.each do |driver_id, rides|
    total = rides.sum { |ride| ride[key] }
    driver_sums[driver_id] = total
  end
  return driver_sums
end

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback! I agree that using more descriptive names improves the readability.

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