Equation to calculate best liked comments

319 Views Asked by At

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?

2

There are 2 best solutions below

0
On

You have to define what criterion will say that a pair $(L_1,D_1)$ for comment 1 is better than $(L_2,D_2)$ for comment 2. One way is just to subtract, so $(L_1,D_1) \geq (L_2,D_2)$ if $L_1-D_1 \geq L_2-D_2$. But on stackexchange there are many more upvotes than downvotes, so maybe you want $(L_1,D_1) \geq (L_2,D_2)$ if $L_1-10*D_1 \geq L_2-10*D_2$ or some such. Maybe you want to compare on $\frac{L-D}{L+D}$. There are many choices, and you need to consider your audience and their behavior to select one. Any such function will map (L,D) to some number, which you can then sort.

2
On

You can try $$f(L,D) = L - D + \frac{1}{D+2}.$$ This would sort first according to $L - D$ (ascending) and then according to $D$ (descending).