【ECMAScript】睡眠、陣列洗牌

翠微發表於2024-05-11
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
},
function shuffleArray(array) {
    for (let i = array.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        let tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }
    return array;
},

相關文章