【发布时间】:2014-05-08 20:23:35
【问题描述】:
这是一个根据 Reddit 的排名算法对项目进行排名的 js 代码。
我的问题是:如何使用此代码对我的 mongodb 文档进行排名?
function hot(ups,downs,date){
var score = ups - downs;
var order = log10(Math.max(Math.abs(score), 1));
var sign = score>0 ? 1 : score<0 ? -1 : 0;
var seconds = epochSeconds(date) - 1134028003;
var product = order + sign * seconds / 45000;
return Math.round(product*10000000)/10000000;
}
function log10(val){
return Math.log(val) / Math.LN10;
}
function epochSeconds(d){
return (d.getTime() - new Date(1970,1,1).getTime())/1000;
}
【问题讨论】:
-
好的,感谢您发布该代码!
标签: javascript mongodb mapreduce