I am building an app for selecting 11 players from Team A and Team B
I am using below logic to select players from Team A and Team B:-
{
name: 'Logic 7',
teamAIndices: [0, 3, 4, 9, 10],
teamBIndices: [0, 1, 4, 5, 7, 10],
captainIndex: [10], // 1st player from Team A
viceCaptainIndex: [6], // 3rd player from Team A
},
But whenever i am selecting teamBIndices(TeamB) last player as 10th (means 11th player) and captainIndex (Means captain of the team) as 10th player (means 11th player of the created team), it is giving me only 10 player. After logging it is found that teamBIndices(TeamB) last player as 10th (means 11th player) is not being selected, but i don’t know why.
Apart from this if i am using below logic, it is creating complete 11 players team:-
{
name: 'Logic 6',
teamAIndices: [1, 4, 5, 6, 8, 10],
teamBIndices: [0, 3, 4, 6, 10],
captainIndex: [6], // 1st player from Team A
viceCaptainIndex: [8], // 3rd player from Team A
},
I need to select 11 players for a team. I am working on javascript.
I am creating team like this:-
function createTeam(teamA, teamB, config) {
const selectedPlayers = [
...config.teamAIndices.map((index) => teamA[index]),
...config.teamBIndices.map((index) => teamB[index]),
];
const captainIndex = config.captainIndex;
const viceCaptainIndex = config.viceCaptainIndex;
// Assign Captain and Vice Captain without adding line breaks
selectedPlayers[captainIndex] += ' (C)';
selectedPlayers[viceCaptainIndex] += ' (VC)';
return selectedPlayers; // Return the array of players
}
2
Answers
Actually the code is ok, the problem with the function i use to remove (C) or (VC) that is placed under the player name in a separate line during creation of team. Below is the code which is deleting the line which contains (C) and (VC) so, if am choosing captainindex(10) it was making Captain to 11th player which was deleted by the function below and moving that (C) to the 10th player:-
You should call:
and
or reset your config to: