examples/game/lib/server.js
function calculateLatency(timestamps){
        var length = timestamps.length,
            sumLatency = 0;

        for (var i = 1; i < length; i++){
            sumLatency += (timestamps[i] - timestamps[i-1])/2;
        }

        return (sumLatency/(length-1));
    }
function calculateLatency(timestamps){
        var length = timestamps.length,
            sumLatency = 0;

        for (var i = 1; i < length; i++){
            sumLatency += (timestamps[i] - timestamps[i-1])/2;
        }

        return (sumLatency/(length-1));
    }
function calculateLatency ( timestamps ) { var length = timestamps . length , sumLatency = 0 ; for ( var i = 1 ; i < length ; i ++ ) { sumLatency += ( timestamps [ i ] - timestamps [ i - 1 ] ) / 2 ; } return ( sumLatency / ( length - 1 ) ) ; }
Helper function that calculates the latency by getting the average of all the ping timestamps differences
@param {Array.<number>} timestamps
@returns {number}
Helper function that calculates the latency by getting the average of all the ping timestamps differences