Last active
November 13, 2019 16:47
-
-
Save JB-CHAUVIN/0dc225725919a2bc42d02a54670971dd 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
let participants = [ | |
'JA', | |
'JB', | |
'Flo', | |
'Raph B', | |
'Raph H', | |
'Stephane', | |
'Laurent', | |
'Alex', | |
'Sevrain', | |
'Tuan', | |
'Nam', | |
'Regis', | |
'Nassim', | |
'Produit' | |
]; | |
let resultat = []; | |
let paire = []; | |
let i = 0; | |
while(participants.length > 0) { | |
let isFirst = i % 2; | |
const max = participants.length; | |
const randomIndex1 = Math.floor(Math.random() * max); | |
const participant1 = participants[randomIndex1]; | |
participants = participants.filter(function(item){ | |
return item != participant1 | |
}); | |
paire.push(participant1); | |
if(isFirst == 1) { | |
resultat.push(paire); | |
paire = []; | |
} | |
i++; | |
} | |
console.log('Result', resultat); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment