Skip to content

Instantly share code, notes, and snippets.

@JB-CHAUVIN
Last active November 13, 2019 16:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JB-CHAUVIN/0dc225725919a2bc42d02a54670971dd to your computer and use it in GitHub Desktop.
Save JB-CHAUVIN/0dc225725919a2bc42d02a54670971dd to your computer and use it in GitHub Desktop.
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