i have array named contents:
contents[0]='<button id=' + randomchar0 +' class="btn" onclick="check('+ f + randomchar0 + f +');">' + randomchar0 + '</button>'; contents[1]='<button id=' + randomchar1 +' class="btn" onclick="check('+ f + randomchar1 + f +');">' + randomchar1 + '</button>'; contents[2]='<button id=' + randomchar2 +' class="btn" onclick="check('+ f + randomchar2 + f +');">' + randomchar2 + '</button>';
i have tried rearrange code:
function shuffle(array) { var currentindex = array.length, temporaryvalue, randomindex ; // while there remain elements shuffle... while (0 !== currentindex) { // pick remaining element... randomindex = math.floor(math.random() * currentindex); currentindex -= 1; // , swap current element. temporaryvalue = array[currentindex]; array[currentindex] = array[randomindex]; array[randomindex] = temporaryvalue; } return array; };
calling this:
shuffle(contents);
from how randomize (shuffle) javascript array?
but method gives me doubles quite often.
any idea how make sure buttons change order without doubling , without using sort()
?
i want rearrange array make buttons in appear in different order everytime output array. dont want of buttons appear twice accident, means need of buttons output in "random" order.
update: found test of array shufflings, there interesting results.
Comments
Post a Comment