react-experiment-hoc
Version:
Simple hoc to provide a/b-test features.
30 lines (22 loc) • 479 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
function _default(weights) {
var totalWeight = 0,
i,
random;
for (i = 0; i < weights.length; i++) {
totalWeight += parseInt(weights[i]);
}
random = Math.random() * totalWeight;
for (i = 0; i < weights.length; i++) {
if (random < parseInt(weights[i])) {
return i;
}
random -= parseInt(weights[i]);
}
return -1;
}
;