reddit投票算法,javascript版本

Reddits voting algorithm, javascript version

本文关键字:javascript 版本 算法 reddit      更新时间:2023-09-26

我试着在javascript中编写这个函数:http://uggedal.com/reddit.cf.algorithm.png:

function getRating(t,u,d){
        var x = u-d;
        if(x > 0)
            y = 1
        else if(x == 0)
            y = 0
        else if(x < 0)
            y = -1
        var z = Math.max(1,Math.abs(x));
        return Math.log(z)/Math.log(10) + y*t/45000;
    }

t =传递给函数的第一篇文章和这篇文章之间的时间(秒)U = upvotesD = downvotes

console.log(getRating(50000, 25, 25)); //0

但是它总是返回0。我错过什么了吗?由于

编辑:更新

对于示例输入,结果是0,所以这是正确的。其他输入是否也返回0 ?

有一点,根据链接,你应该设置

z = Math.max(1,Math.abs(x))

在这种情况下,z等于1,log(1)等于0。此外,"y"将为0,因为u == d。

正如在问题的评论中提到的,从链接的。png文件中可以清楚地看到,您需要从"x"和1的绝对值的最大值设置"z"。当"u"answers"d"相同时,它总是0