Skip to content

Instantly share code, notes, and snippets.

@kentaro-m
Created January 19, 2020 05:53
Show Gist options
  • Save kentaro-m/43bedebb9c029b6ae3e48553e93cd160 to your computer and use it in GitHub Desktop.
Save kentaro-m/43bedebb9c029b6ae3e48553e93cd160 to your computer and use it in GitHub Desktop.
Kanazawa.js meetup #1 のLT発表順を決めるJavaScript
/**
* 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