I solved it, testing everything from a 3x3 to a 6x6 (1 - 36). I traced a given input, doing a loop in my head and realized if the array was even, it would be for example (array is 8 x 8, you’d go through it 12 times. If it’s 4 you’d go through it 6 times). If it was odd, for example 9 you’d still go through it 13 times. If it’s 5 you’d go through it 7 times.
So I did a greater loop that looked like
for (var entire = 0; entire < array.length + Math.floor(array.length / 2); entire++)
Within the entire loop I first pushed the entire first nested array into a variable result (which I created outside of the loop obviously). I then splice it from the array. Then I added two sepparate loops within entire, one called down and the other called up. In between I push the entire last nested array, reversed, into result. Then splice it out.
Down starts at 1 (array has been pushed in its entirety and spliced away at this point) and goes up while it’s less than array.length - 1. For each index it pushes, then splices the last index of each nested array.
Then I push the final nested array, reversed into result and splice it away.
Then up starts at array.length - 1 and goes to 0. For each index, it pushes the first index of the nested array and splices it away.
I then concat result together with a reduce function.
In some cases (when the array was large and even), there ended up being an ‘undefined’ at the end, so I did an if statement testing whether ‘undefined’ was included in result. If so, I pop it away. Then return result.
Can anyone give me some TDD tests to put in?