how divide sum on 7 elements in array with max and min (between 1-10) javascript

Viewed 47

I have a game ... a football club, the coach decided to make a friendly match between team members, 14 each theeach The player has a rating out of 1-10. Requirement:

  • Create two teams of 7 players so that the sum of the player's rating is equal for each team, and team 2 depends only on the the sum of team one

This is my code create team 1

let team_1_rates = [];
let team_2_rates = [];

for (let i = 0; i < 7; i++) {
 let rate = Math.ceil(Math.random() * 10);
  if (team_1_rates.indexOf(rate) === -1) {
    team_1_rates.push(rate);

$('#here_table').append('<tr><td>' + team_1_rates[i] + '</td> 
  </tr>');
} else
   i--;
}

let sum = 0
   for (let x = 0; x < team_1_rates.length; x++) {
        sum += team_1_rates[x]
}
  $('#here_table').append('<tr><td>' + sum + '</td></tr>');

how can I do the same rate for Team_tow 2? I tried a percentage and other ways but without any result

0 Answers
Related