2
$\begingroup$

In my website, users can either "like" or "dislike" a posted comment. I want to put a link to sort comments by liking such that the most liked ones becomes on top.

Of course I cannot just sort by the number of likes only. I have to subtract the dislikes. But what if the difference (likes - dislikes) are the same. e.g. 10 - 8 = 2 and 5 - 3 = 2. I think in this case, the comment of 10 likes and 8 dislikes has to come before the 5 likes and 3 dislikes comment.

So is there an equation that you feed it the number of likes and number of dislikes and then it gives you a meaningful rating number that I can sort with?

  • 0
    Why can't you code this directly? Given a list pick largest "like-dislike" and if two are equal sort by largest "like"?2010-11-27
  • 0
    Yes, your criterion defines a perfectly good [total order](http://en.wikipedia.org/wiki/Total_order) relation. Doesn't your programming language allow you to sort using arbitrary user-defined comparison functions?2010-11-27
  • 1
    ...Although you should really look at [How Not To Sort By Average Rating](http://www.evanmiller.org/how-not-to-sort-by-average-rating.html) by Evan Miller, which solves your underlying problem and not just the symptom.2010-11-27
  • 0
    There are many algorithms used for this problem because there are many ways to interpret and to use the data. One very different strategy would be to put comments on top if they've been rated many times, with a mix of likes and dislikes. That means people are interested in the comment and are likely to respond. (This could lead to intelligent debate or to name-calling, but both can result in more people visiting your site.)2010-11-28
  • 0
    Jonas Kibelbek, what would that algorithm look like?2010-11-29
  • 0
    A friend suggested (L*(L-D))/(L+D+1). I don't know where he got it from. Would it work?2010-11-29

3 Answers 3