Fisher Yates Adding Duplicates

95 views Asked by At

I'm trying to shuffle 6 T's and 6 A's and loop until the end of the array is reached. However, I keep getting uneven amounts of T's and A's displayed as I am looping. I'm new to javascript and not sure if the issue is related to the shuffle or loop.

//function to shuffle word array
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// remaining elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
    return array;
}
var wordt= ["T", "A","T", "A","T", "A","T", "A","T", "A","T", "A"]; //Your words
shuffle(wordt)
var i = 0;
    var currentWordt = 0;
    //pull T/A
    while (12 !==currentWordt) {
    var my_wordt =  wordt[i];
    var nb = jQuery('#NextButton');
    nb.val(my_wordt);
    nb.attr('title', my_wordt);
    i +=1
    currentWordt += 1
    }
0

There are 0 answers