Skip to content

Instantly share code, notes, and snippets.

@michaelcaxias
Last active March 11, 2022 14:36
Show Gist options
  • Save michaelcaxias/08a3f4a9045d79bd100fff218ae5af94 to your computer and use it in GitHub Desktop.
Save michaelcaxias/08a3f4a9045d79bd100fff218ae5af94 to your computer and use it in GitHub Desktop.
const sortGroups = (summers: string[]) => {
let currentIndex = summers.length, temporaryValue: string, randomIndex: number;
while (currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = summers[currentIndex];
summers[currentIndex] = summers[randomIndex];
summers[randomIndex] = temporaryValue;
}
return {
pair1: summers.slice(0, 2),
pair2: summers.slice(2, 4),
pair3: summers.slice(4, 6),
}
}
const allPeople = ['Michael', 'Jonathan', 'Murilo', 'Bica', 'Alexandre', 'Wesley']
console.log(sortGroups(allPeople));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment