I have created a random team generator with Javascript and it works to generate two random teams of five players each. This is how it looks : 
and I created a function to determine the value of each rank :
function getRankValue(rank) {
let rankValue;
    switch(rank) {
        case "platinum1" : rankValue = 2100;
        break;
        case "platinum2" : rankValue = 2000;
        break;
        case "platinum3" : rankValue = 1900;
        break;
        case "platinum4" : rankValue = 1800;
        break;
        case "gold1" : rankValue = 1650;
        break;
        case "gold2" : rankValue = 1550;
        break;
        case "gold3" : rankValue = 1450;
        break;
        case "gold4" : rankValue = 1350;
        break;
        case "silver1" : rankValue = 1200;
        break;
        case "silver2" : rankValue = 1100; 
        break;
        case "silver3" : rankValue = 1000;
        break;
        case "silver4" : rankValue = 900;
        break;
        case "bronze1" : rankValue = 750;
        break;
        case "bronze2" : rankValue = 650; 
        break;
        case "bronze3" : rankValue = 550;
        break;
        case "bronze4" : rankValue = 450;
        break;
        case "iron1" : rankValue = 300;
        break;
        case "iron2" : rankValue = 200;
        break;
        case "iron3" : rankValue = 100;
        break;
        case "iron4" : rankValue = 0;
        break;
    }
    return rankValue;
I want to make the generator create teams based on the players rank value to create a balanced total team value. For example :
4x Silver4(900 value each) & 1x bronze 4 (450 value) for a total value of 4050 versus :
3x Silver1(1200 value each) & 2x iron2(200 value each) for a total value of 4000. I want to make it have some room for +- 200 value, otherwise it would be too complex.
How should the algorithm look like?
 
    