Answer the question
In order to leave comments, you need to log in
How to make smaller numbers give more points?
I subtract the posting time for the present (example: 1493490780-1493487180) and I need to sort by the most relevant posts, I can do this, but I need to make points according to the "less is better" algorithm,
subtraction gives equality, for example ,
up to 3600 then points will be 50000
from 3601 to 7200 points 25000
from 7201 to 10800 points 10000
Answer the question
In order to leave comments, you need to log in
Literally, your rules are implemented by similar JavaScript code - with conditions:
function getPostScore(time) {
var diff = Math.floor((new Date()).getTime()/1000) - time;
if( diff <= 3600) return 50000;
else if( diff <= 7200) return 25000;
else if( diff <= 10800) return 10000;
else return 0;
}
getPostScore(1493487180); // 10000
y = k / x
k = 50000 * 3600
, it successfully captures the second point as well. But it is bad because closer to zero it goes off scale to + infinity. function getPostSigma(time){
var diff = Math.floor((new Date()).getTime()/1000) - time;
return Math.round( 10000 + 40000 / (1 + Math.exp((diff-6800)/700)));
}
getPostSigma(1493531780); // 49998
getPostSigma(1493522780); // 11545
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question