Created
June 7, 2015 18:03
-
-
Save federicobucchi/eeec5730b22be01522e8 to your computer and use it in GitHub Desktop.
A/B Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test1 = { 30: 'Template A', 60: 'Template B', 10: 'Template C' }; | |
var test2 = { 30: 'Template A', 70: 'Template B' }; | |
var test3 = { 'A': 50, 'B': 50 }; | |
function selectEnv(templates) { | |
var newTemplates = {}; | |
var tot = 100; | |
var random = Math.floor(Math.random() * 100); | |
var i; | |
var y; | |
if (Object.keys(templates).length === 2) { | |
if (templates[Object.keys(templates)[0]] + templates[Object.keys(templates)[1]] === 100) { | |
if (random <= 50) { | |
return Object.keys(templates)[1]; | |
} else { | |
return Object.keys(templates)[0]; | |
} | |
} | |
} | |
for (key in templates) { | |
for (i = Object.keys(templates).length; i > 0; i--) { | |
for (y = tot; y >= tot - key; y--) { | |
newTemplates[y] = templates[key]; | |
} | |
} | |
tot = tot - key; | |
} | |
return newTemplates[random]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment