I am struggling with a coding problem involving adding users to groups. The goal is to add each user to a group array, with a maximum of 3 users per group. If a group reaches 3 users, it should be moved to another array that collects all the groups. I then need to start a new group for the next 3 users until all users are assigned to groups.
Error -
let group[i] = [];
Unexpected token [
I've been working on this challenge for some time now and can't seem to crack it. It feels like I've hit a wall.
Here's the code snippet where I'm facing issues:
function createGroups(totalPeople){
let i = 1
let group[i] = [];
let array = totalPeople
totalPeople.map((user) => {
if(group[i] < 3){
group[i].push(user)
}else{
array.push(group[i]);
i++
}
})
};
The 'totalPeople' array is generated earlier in my script, and this portion seems to be causing trouble. Any suggestions or corrections to help me solve this puzzle would be greatly appreciated! Thank you!