I need to go through a simple array in a "weird" way.
The length of my array is always an odd number.
Say the length is 49. To make it clearer, my elements are the index of the array. So I have something like:
myArray = [0, 1, 2, 3, 4 ... 47, 48]
So you can imagine the following square matrix:
0 7 14 21 28 35 42 1 8 15 22 29 36 43 2 9 16 23 30 37 44 3 10 17 24 31 38 45 4 11 18 25 32 39 46 5 12 19 26 33 40 47 6 13 20 27 34 41 48
I need to start from the center of this matrix (ie myArray[Math.floor(myArray.length / 2)] )
In my example: 24
Then I have to alternate the left and right numbers until I go through the entire line.
In my example for the first iteration: 17, 31, 10, 38, 3, 45
After the line is completed, I alternate between the upper and lower digits, I repeat the left / right logic for this line.
In my example, to enter myArray as an input value, I have to loop in the following order:
24, 17, 31, 10, 38, 3, 45, 23, 16, 30, 9, 37, 2, 44, 25, 18, 32, 11, 39, 4, 46, 22, 15, 29, 8, 36, 1, 43, 26, 19, 33, 12, 40, 5, 47, 21, 14, 28, 7, 35, 42, 0, 27, 20, 34, 13, 41, 6, 48
Could you help me in what has been achieved?
Here is what I have done so far: https://jsfiddle.net/6qzkk2zx/