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

Week 2 assignment #86

Open
wants to merge 2 commits into
base: week2_assignment
Choose a base branch
from

Conversation

suchit07-git
Copy link

No description provided.

@suchit07-git
Copy link
Author

Screenshot 2022-12-31 161259
Screenshot 2022-12-31 161834

@hrushikeshj hrushikeshj mentioned this pull request Jan 2, 2023
Copy link
Collaborator

@hrushikeshj hrushikeshj left a comment

Choose a reason for hiding this comment

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

Good job

Comment on lines +134 to +136
pets.group_by { |pet|
res[pet.animal_type_id].push(pet.name)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong use of group_by, group_by is used for grouping items from an enumerable and return a hash. Since you are just iterating each itself can be used here.

You can also use a single each block to so this.

pets.each do |pet|
  if res[pet.animal_type_id]
      # ....
  else
      res[pet.animal_type_id] = [pet.name]
   end
end  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants