-
Notifications
You must be signed in to change notification settings - Fork 0
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
oop task done #1
base: master
Are you sure you want to change the base?
Conversation
|
end | ||
|
||
def most_active_reader | ||
data_module.fetch_orders.group_by { |order| order.reader }.sort_by { |_, value| value.length }.to_a.last.first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group_by(&:reader)
|
||
def three_popular_books_orders | ||
books = group_orders_by_books.last(3).map { |item| item.first } | ||
book_ids = books.map { |book| book.id } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map(&:first).map(&:id)
else | ||
nil | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now method is very long and are several extra actions
There are several possibilities here:
- data_module.fetch_orders.select { |order| book_ids.include? order.book.id }.map(&:reader)
- data_module.fetch_orders.map { |order| order.reader if book_ids.include? order.book.id }.compact
According to task you should return count of uniq readers who takes at least one of 3 most popular books. Are you sure that you need to return books and readers.
Also you don't need to use return in the line 30
private | ||
|
||
def group_orders_by_books | ||
data_module.fetch_orders.group_by { |order| order.book }.sort_by { |_, value| value.length }.to_a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group_by(&:book)
No description provided.