react-experiment-hoc
Version:
Simple hoc to provide a/b-test features.
26 lines (19 loc) • 417 B
JavaScript
function X(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;
};
for (var i=0;i<10000;i++) {
console.log(X([0,100]));
}