How to create balanced teams by skill levels

Do you have a tutorial for: creating groups(teams) based on skill level? Example; I have a class of kids that like to play ‘darts’. Each of the kids have different skill levels. I create the teams(groups) with kids of a variety of skill levels so that the teams are closely balanced. Example: 10 kids - 2 teams: teamA (skillLevels: 1, 1, 2, 3, 5) and teamB(skillLevels: 2, 3, 3, 4, 1) I would like to have the app randomly create the teams and not have to hard code it, so that the team players can shuffle around to make it more interesting for the kids.
thank you

Whether or not this makes a good team depends on how good your assessment of skill is. It’s a little bit of a problem because if you have nine players of skill 1 and one player of skill 9 and you need even numbers on the teams there is just no way to balance the teams.

There isn’t a tutorial for this so far but here’s how I’d get started:

Take all your players and the skill numbers assigned to them. Add all the numbers. Divide by the number of teams you want to make and that is your target score. Arrange all of your players in a dictionary of arrays, where each dictionary key is a score number and each array is a list of players having that ability score. Take the array of keys from the dictionary and sort them highest to lowest. Now alternating between teams, take the array representing players having the highest ability score and remove it from the dictionary. Alternating between teams, add a player in turn to each team adding the ability score to the team’s cumulative score. Repeat for each descending ability score until all players are distributed.

If you can have uneven numbers of people on each team then after selecting a player from the highest ability group, keep selecting players for the next team until enough players have been added to bring the team score up to the score achieved by the first team.