I have an array of teams, I am trying to split that array into multiple arrays with having minimum players in each array. I mean, form the array into multiple teams from array. I forgot what this feature is called, but let me tell you with an explanation:
minimum players: 3
team array: [4, 6, 5, 8]
This array will form like this:
[
[4, 6, 5],
[4, 6, 8],
[4, 5, 8],
[6, 5, 8],
[4, 6, 5, 8]
]
So, I have tried doing this problem, but I got stuck that what to do and how to do.
function teams(minPlayers, arr) {
for (let i = 0; i < arr.length; i++) {
const subArray = []
let startMax = minPlayers - 2
let end = minPlayers
for (let j = 0; j < arr.length; j++) {
if (j < startMax) {
subArray[i] = arr[i]
}
}
}
}
console.log(teams(3, [4, 6, 5, 10]))
It will be a pleasure if you help me.