0


Sorry for the noob question (i guess...).

Say I have an array of post_commenters with user_id & comment_id
E.g.:
1 - 27
2 - 31
1 - 54
3 - 87
1 - 12
2 - 54

If I wanted to rank the users by their number of comments, I'd have to count the number of times they have commented, and then .uniq it.

How can I do that ?

I know how to uniq it:

unique_user_list = array.uniq {|s| s.user_id}

I know how to count the duplicates inside the array:

array.count { |u| u.name == unique_user_list.name  } # in a loop of user

But i'm at a loss to mix and sort by number of duplicates...
Thank you!

EDIT

Ok, thanks to floatless, i'm now at something more tangible - with a real example from the foursquare api, using quimby gem:

- current_user.all_checkins.group_by(&:venue["id"]).first(50).each do |c|
  = c.venue.id

Only problem, it doesn't .... group.
Any idea?

1 Answer 1

1

I think you should use a GROUP BY clause inside your SQL query to do that and then just COUNT grouped comments.

Sign up to request clarification or add additional context in comments.

1 Comment

My example was a dummy example - i'm getting an array from an api, don't think the group_by works here...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.