]> git.scottworley.com Git - reliable-chat/commitdiff
Fix odd case of median
authorScott Worley <sworley@chkno.net>
Fri, 3 Aug 2012 19:20:43 +0000 (12:20 -0700)
committerScott Worley <sworley@chkno.net>
Fri, 3 Aug 2012 19:20:43 +0000 (12:20 -0700)
webclient/rc.html

index 27dba592d9ba4cc0638cbe385545635c29691c0a..e497135b1776c630445b0a5819add40abf6404aa 100644 (file)
                        times.push(message.ServerTimes[i]);
                }
                times.sort();
-               var middle = times.length/2;
                if (times.length % 2) {
-                       message.Time = times[middle];
+                       message.Time = times[(times.length-1)/2];
                } else {
+                       var middle = times.length/2;
                        var difference = times[middle].getTime() - times[middle-1].getTime();
                        message.Time = new Date(times[middle-1].getTime() + difference/2);
                }