I would be grateful if someone could help me get unstuck. I have an array which I would like to describe using an object. The array looks like this:
const numberGroupArray = [
'GROUP_A',
'ONE',
'TWO',
'BREAK',
'FOUR',
'GROUP_B',
'SIX',
'GROUP_C',
'EIGHT',
'BREAK',
'TEN',
'ELEVEN',
'GROUP_D',
'THIRTEEN',
'BREAK',
'FIFTEEN',
'BREAK',
'SEVENTEEN',
'EIGHTEEN',
'NINETEEN',
]
And the goal object looks like this:
const numberInGroup = {
GROUP_A: [[1, 2], [4]],
GROUP_B: [[6]],
GROUP_C: [[8], [10, 11]],
GROUP_D: [[13], [15], [17, 18, 19]],
};
Where each number refers to an index from the array above. numberInGroup.GROUP_A[0][1] refers to 'TWO' in the array above. Similarly, numberInGroup.GROUP_D[2][1] refers to 'SEVENTEEN'.
Attempting to work through the creation of the object:
- 'GROUP_A' is set
- A working array is created and strings 'ONE' and 'TWO' are pushed to 'GROUP_A'.
- A 'BREAK' creates a new working array and 'FOUR' is pushed to 'GROUP_A'.
- 'GROUP_B' is set and steps 2 and 3 repeat for the rest of the initial array.
If you need more info, happy to provide. Thank you in advance.