Last active
March 11, 2022 14:36
-
-
Save michaelcaxias/08a3f4a9045d79bd100fff218ae5af94 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 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