JSFiddle - React, Tailwind, and code Playground
JavaScript
tic = 21600; // UNIX time on January 1st, 1970 (0:0:0)
toc = 1325376000; // UNIX time on January 1st, 2012 (0:0:0)
toc2 = 1328076000; // UNIX time on February 1st, 2012 (0:0:0)
toc3 = 1330581600; // UNIX time on March 1st, 2012 (0:0:0)
toc4 = 1325656800; // UNIX time on March 1st, 2012 (0:0:0)
toc5 = 1325743200; // UNIX time on March 1st, 2012 (0:0:0)
toc6 = 1325829600; // UNIX time on March 1st, 2012 (0:0:0)
toc7 = 1325916000; // UNIX time on March 1st, 2012 (0:0:0)
pA = tic;
tic = tic + 86400;
votA = 0;
while(tic < toc)
{
//A receives a vote each day till 2012
pA = (pA + tic)/2;
votA = votA + 1;
tic = tic + 86400; //Add 1 day
}
// Itemp B was created on January 1st, 2009 (0:0:0)
Y2009 = 1230768000; // UNIX time on January 1st, 2009 (0:0:0)
// Item B recieves 1 vote on January 1st, 2012 (0:0:0)
pB = (Y2009 + toc)/2; // pB is the popularity value for item B
pB = (pB + toc2)/2; // Item B receive its 2nd vote on February 1st, 2012
pB = (pB + toc3)/2; //Item B receive its 3rd vote on March 1st, 2012
pB = (pB + toc4)/2; //Item B receive its 4th vote on April 1st, 2012
pB = (pB + toc5)/2; //Item B receive its 5th vote on May 1st, 2012
pB = (pB + toc6)/2; //Item B receive its 6th vote on June 1st, 2012
pB = (pB + toc7)/2; //Item B receive its 7th vote on July 1st, 2012
if (pA > pB) {
alert("Item A (" + votA + " votes) has a higher popularity by " + Math.round(pA - pB));
}
if (pB > pA) {
alert("Item B (7 votes vs " + votA + " votes) has a higher popularity by " + Math.round(pB - pA));
}