Skip to content

Instantly share code, notes, and snippets.

@shajanjp
Created August 23, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shajanjp/0ad1dcfef4fcf85793f2f3c37a3c787d to your computer and use it in GitHub Desktop.
Save shajanjp/0ad1dcfef4fcf85793f2f3c37a3c787d to your computer and use it in GitHub Desktop.
let people = [
["Arun Prabhakaran",
"Abhilash Pillai",
"Vishnu Agikumar",
"Lovegin John",
"Akhilesh PV",
"Bibin Binny Mathew ",
"Amal Babu"],
["Akhil Xavier",
"Ramees P.U",
"Ashok Saravanan S",
"Nithin C.S",
"Arun George",
"Vipin Chandran",
"Aravind M",
"Libin Thomas",
"Alen Thomas V",
"Anoop ML",
"Anandu Viswan",
"Sijoy Jos",
"Vivek Joy"],
["Akhil Raj ",
"Jithin T C",
"Vishal Vijayan",
"Mathews T Abraham",
"Mithun Raj",
"Jinil KS",
"Vijay C",
"Sreehari K",
"Muhammed Fasil",
"Shajan Jacob",
"Vineeth Vijayan",
"Eldho Kuriakose",
"Jomon C Antony",
"Midhun KM"],
["Dibin Kumar C",
"Manu Joseph ",
"Steephen Varghese",
"Vivek Dinesh ",
"Hebin Jose C ",
"Akhil Ben",
"Rony James ",
"Rahul Ravi",
"Rahul Joseph",
"Aravind Ravi",
"Anto Abraham"
],
["Nimmi A",
"Chippy Kuriakose",
"Salu Kumar",
"Anju P Lekshmi",
"Lekshmipriya M",
],
[
"Chinnu Rose Joseph",
"Jeena PV",
"Divya Alex",
"Jane Goerge ",
"Ann AlphonsaAntony",
"Sini Oommen",
"Safiya Saleem",
"Athira KA ",
]
]
let shuffledPeople = [];
function generateRandomNumber(min, max){
return Math.floor(Math.random() * (max-min) + min);
}
function shaffle(ordered){
let shuffled = [];
for(var i=ordered.length; i>0; i--){
let r =generateRandomNumber(0, i);
shuffled.push(ordered.splice(r, 1)[0])
}
return shuffled;
}
people.forEach(c => {
shuffledPeople = shuffledPeople.concat(shaffle(c));
})
console.log('people to split', shuffledPeople, shuffledPeople.length);
let team = [[],[],[],[]];
let teamIndex = 0;
shuffledPeople.forEach(p => {
team[teamIndex].push(p)
if(teamIndex < 3){
teamIndex++
}
else{
teamIndex = 0;
}
})
console.log('team 1', team[0], team[0].length);
console.log('team 2', team[1], team[1].length);
console.log('team 3', team[2], team[2].length);
console.log('team 4', team[3], team[3].length);
console.log('len', team[0].length +
team[1].length +
team[2].length +
team[3].length );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment