Fisher Yates 添加重复项

问题描述

我正在尝试打乱 6 个 T 和 6 个 A 并循环直到到达数组的末尾。但是,在循环播放时,T 和 A 的显示数量一直不均匀。我是 JavaScript 新手,不确定问题是否与随机播放或循环有关。

//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"]; //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
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)