Last active
August 18, 2020 16:09
-
-
Save timknip/1587a60a700951a89e48f922a149a763 to your computer and use it in GitHub Desktop.
Ficus Loterij
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Shuffles array in place using the Fisher-Yates algorithm. | |
* @see https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm | |
* | |
* @param {Array} a items An array containing the items. | |
*/ | |
function shuffle(a) { | |
for (let i = a.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[a[i], a[j]] = [a[j], a[i]]; | |
} | |
return a; | |
} | |
const deelnemers = [ 'jullie', 'namen', 'hier' ]; | |
shuffle(deelnemers) | |
.forEach((deelnemer, stand) => console.log(`${stand+1}.\t${deelnemer}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment