1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| var a = [1, 2, 3, 4, 5];
function randomSort(arr) { for (let i = 0, len = arr.length; i < len; i++) { let random = Math.floor(Math.random() * len); let cur = arr[i]; arr[i] = arr[random]; arr[random] = cur; } } randomSort(a); console.log(a);
|