打亂陣列

weixin_34124651發表於2018-03-28
    function Daluan(arr) {

        var tmpArray = arr.slice(0);
        console.log(tmpArray);
        var result = [];
        while (tmpArray.length >= 1) {
            var randomIndex = Math.floor(Math.random() * tmpArray.length);
            var value = tmpArray[randomIndex];
            result.push(value);
            tmpArray.splice(randomIndex, 1);
        }

        return result;
    }

相關文章