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

oop task done #1

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

oop task done #1

wants to merge 5 commits into from

Conversation

yareg
Copy link
Owner

@yareg yareg commented Oct 23, 2016

No description provided.

@yamnich
Copy link

yamnich commented Nov 14, 2016

  1. Create fetch and add methods with metaprogramming
  2. Optimise select readers count method

end

def most_active_reader
data_module.fetch_orders.group_by { |order| order.reader }.sort_by { |_, value| value.length }.to_a.last.first
Copy link

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 }
Copy link

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
Copy link

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:

  1. data_module.fetch_orders.select { |order| book_ids.include? order.book.id }.map(&:reader)
  2. 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
Copy link

Choose a reason for hiding this comment

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

group_by(&:book)

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