美文网首页
打乱数组

打乱数组

作者: 柠檬不萌5120 | 来源:发表于2018-03-28 12:44 被阅读0次
    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;
    }

相关文章

网友评论

      本文标题:打乱数组

      本文链接:https://www.haomeiwen.com/subject/iopycftx.html