My child's baseball team consists of 13 players. In order to ensure that each player has an equal opportunity to play different positions, I devised a JavaScript algorithm. However, the current algorithm does not seem to be distributing the positions fairly and is quite confusing. Can anyone suggest a simpler and more effective approach?
var kids = new Array("Amelie","Avery","Brennan","Clayton","Devin","Flynn","Haydn","Jack","Kai","Liam","Max","Maxi","Sterling");
var kids_copy = kids.slice(0);
var positions = new Array("Pitcher","Catcher","Third Base","Short Stop","Second Base","First Base","Right Field","Ctr Right","Ctr Left","Left");
var positions_copy = positions.slice(0);
var assignment = new Array();
for(i=0;i<positions_copy.length;i++){
j = i%positions.length;
assignment[j] = new Object();
for(h=0;h<kids_copy.length;h++){
if((positions[0]) && (kids[0])){
role = positions[0].trim();
person = kids[0].trim();
assignment[j][role] = person;
}
var shifted = kids.shift();
kids.push(shifted);
var position_shifted = positions.shift();
positions.push(position_shifted);
}
var shifted = kids.shift();
kids.push(shifted);
}
for(i=0;i<assignment.length;i++){
console.log("\nIteration: " + (i+1));
for(h=0;h<positions_copy.length;h++){
l = positions_copy[h];
console.log(l + '=' + assignment[i][l]);
}
}