Skip to content

Instantly share code, notes, and snippets.

@timknip
Last active August 18, 2020 16:09
Show Gist options
  • Save timknip/1587a60a700951a89e48f922a149a763 to your computer and use it in GitHub Desktop.
Save timknip/1587a60a700951a89e48f922a149a763 to your computer and use it in GitHub Desktop.
Ficus Loterij
/**
* 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