With regards to marking this as answered by another question, please take note that this is not a flat array but an array of arrays. Additionally, the numbers provided are just examples for visual representation.
I am attempting to iterate through an array of arrays with the following structure:-
[
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[3, 2, 1, 6, 5, 4, 9, 8, 7],
[6, 5, 4, 9, 8, 7, 3, 2, 1],
[7, 8, 9, 3, 2, 1, 6, 5, 4]
]
How can I transform this array into chunks of 3x3 like so:-
[
[1, 2, 3, 1, 2, 3, 1, 2, 3],
[4, 5, 6, 4, 5, 6, 4, 5, 6],
[7, 8, 9, 7, 8, 9, 7, 8, 9],
[3, 2, 1, 6, 5, 4, 9, 8, 7],
[6, 5, 4, 9, 8, 7, 3, 2, 1],
[7, 8, 9, 3, 2, 1, 6, 5, 4],
]
I have chunked the array using the first 3 values from each sub-array, followed by the next 3 values, and then the final 3 values.
The resulting chunked array should appear as follows:-
1 2 3 | 4 5 6 | 7 8 9
1 2 3 | 4 5 6 | 7 8 9
1 2 3 | 4 5 6 | 7 8 9
---------------------
3 2 1 | 6 5 4 | 9 8 7
6 5 4 | 9 8 7 | 3 2 1
7 8 9 | 3 2 1 | 6 5 4
I have attempted iterating through each row, resetting the column count upon reaching an increment, and increasing the row number accordingly, but this approach was not successful.
I am willing to provide details of my previous attempts if it would be beneficial. Additionally, it's worth noting that the size of the array may vary but will always be divisible by a specific number, which in this instance is 3.
Further information has been added to the question. The array of arrays will consistently be divisible by a particular numerical value, with the current example demonstrating a divisibility by 3.