{"ScriptPreparationCode":"var variants = [{ id: 1, weight: 1}, { id: 2, weight: 10 }, { id: 3, weight: 10 }, { id: 4, weight: 10 }, { id: 5, weight: 10 }];\r\nvar totalWeight = variants.reduce((sum, item) =\u003E sum \u002B item.weight, 0);\r\nvar scores = Array.from({ length: 10 }).map(() =\u003E { Math.trunc(Math.random() * totalWeight) });\r\n\r\nvar forofreturn = (score) =\u003E {\r\n for (const variant of variants) {\r\n if (score \u003C variant.weight) {\r\n return variant;\r\n }\r\n score -= variant.weight;\r\n }\r\n}\r\n\r\nvar whileloopindex = (score) =\u003E {\r\n var index = 0;\r\n while (score \u003E 0) {\r\n score -= variants[\u002B\u002Bindex].weight;\r\n }\r\n\r\n return variants[index];\r\n}","TestCases":[{"Name":"forofreturn","Code":"forofreturn(scores[0]);\r\nforofreturn(scores[1]);\r\nforofreturn(scores[2]);\r\nforofreturn(scores[3]);\r\nforofreturn(scores[4]);\r\nforofreturn(scores[5]);\r\nforofreturn(scores[6]);\r\nforofreturn(scores[7]);\r\nforofreturn(scores[8]);\r\nforofreturn(scores[9]);","IsDeferred":false},{"Name":"whileloopindex","Code":"whileloopindex(scores[0]);\r\nwhileloopindex(scores[1]);\r\nwhileloopindex(scores[2]);\r\nwhileloopindex(scores[3]);\r\nwhileloopindex(scores[4]);\r\nwhileloopindex(scores[5]);\r\nwhileloopindex(scores[6]);\r\nwhileloopindex(scores[7]);\r\nwhileloopindex(scores[8]);\r\nwhileloopindex(scores[9]);","IsDeferred":false}]}