编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
let shuffle = function (arr){
    let result = [],
        random = 0
    while(arr.length){
        random = Math.floor(Math.random()*arr.length)
        result.push(arr[random])
        arr.splice(random,1)
    }
    return result
}

console.log(shuffle([1,2,3,4,5,6,7,8]))