Created
January 19, 2020 05:53
-
-
Save kentaro-m/43bedebb9c029b6ae3e48553e93cd160 to your computer and use it in GitHub Desktop.
Kanazawa.js meetup #1 のLT発表順を決めるJavaScript
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
/** | |
* Fisher-Yates algorithmに基づいたシャッフル関数 | |
* 30-seconds-of-codeの実装例より | |
* @see https://github.com/30-seconds/30-seconds-of-code/blob/master/snippets/shuffle.md | |
*/ | |
const shuffle = ([...arr]) => { | |
let m = arr.length | |
while (m) { | |
const i = Math.floor(Math.random() * m--) | |
;[arr[m], arr[i]] = [arr[i], arr[m]] | |
} | |
return arr | |
} | |
const speaker = [ | |
'saitoeku3', | |
'DaikiTeramoto', | |
'mugi_uno', | |
'uruha', | |
'Kentaro', | |
'yu_kgr', | |
] | |
console.log(shuffle(speaker)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment