@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
19 lines (18 loc) • 646 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.findLatencyIndex = void 0;
var lang_1 = require("../utils/lang");
var MIN = 0;
var MAX = 22;
var BASE = 1.5;
/**
* Calculates buckets from latency in milliseconds
*
* @param latencyInMs - latency in milliseconds
* @returns a bucket index from 0 to 22 inclusive
*/
function findLatencyIndex(latencyInMs) {
var index = Math.min(MAX, Math.max(MIN, Math.ceil(Math.log(latencyInMs) / Math.log(BASE))));
return (0, lang_1.isNaNNumber)(index) ? 0 : index; // index is NaN if latency is not a positive number
}
exports.findLatencyIndex = findLatencyIndex;
;