Open Sunny-117 opened 7 months ago
function shuffle(array){ for(let i = array.length - 1; i>=0; i--){ const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array } // 测试 const arr = [1, 2, 3, 4, 5]; const shuffledArr = shuffle(arr); console.log(shuffledArr);