| 498 | } |
| 499 | |
| 500 | function shuffle(array) { |
| 501 | let counter = array.length; |
| 502 | if (counter <= 1) return array; |
| 503 | |
| 504 | // While there are elements in the array |
| 505 | while (counter > 0) { |
| 506 | // Pick a random index |
| 507 | const index = Math.floor(Math.random() * counter); |
| 508 | |
| 509 | // Decrease counter by 1 |
| 510 | counter--; |
| 511 | |
| 512 | // And swap the last element with it |
| 513 | const temp = array[counter]; |
| 514 | array[counter] = array[index]; |
| 515 | array[index] = temp; |
| 516 | } |
| 517 | return array.filter(Boolean); |
| 518 | } |
| 519 | |
| 520 | async function Queue(list, context, type) { |
| 521 | const count = list.length; |