Created
August 6, 2021 12:03
-
-
Save takapiro99/31605c39bc1ad2803b91312f034083d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const chantoSort = (array) => { | |
for (let i = array.length - 1; i > 0; i--) { | |
let r = Math.floor(Math.random() * (i + 1)); | |
let tmp = array[i]; | |
array[i] = array[r]; | |
array[r] = tmp; | |
} | |
return array; | |
}; | |
const splitArray = (array, n) => | |
array.reduce( | |
(a, c, i) => | |
i % n == 0 ? [...a, [c]] : [...a.slice(0, -1), [...a[a.length - 1], c]], | |
[] | |
); | |
const participants = [...Array(10).keys()]; | |
let count = 0; | |
const sets = []; | |
for (let i = 0; i < 5; i++) { | |
const shuffled = chantoSort([...participants]); | |
sets.push(shuffled); | |
count++; | |
} | |
console.log(sets.map((set, i) => `set ${i}: ${splitArray(set, 2).map((item, idx)=>(`room${idx}: ${item.join("-")}`))}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment