Question: Write a function called unroll, which takes in a square array of arrays (i.e. a grid with n rows input could look like this: const

 Write a function called unroll, which takes in a square array

Write a function called unroll, which takes in a square array of arrays (i.e. a grid with n rows input could look like this: const square = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] 1; unroll should take in such a square array and return a single array containing the values in the obtain the values by traversing the square in a spiral: from the top-left corner, move all the wa all the way down, then all the way to the left, then all the way up, and repeat. For the above example, unroll should return [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 10] . Here's another example: const smallerSquare = [ ["a", "b", "c"] , ["d', "e"l, "f"l] , ["g", "h", "i"] ; unroll (smallerSquare) ; // ["a", "b", "c", "f", "ill, "h", "gl, "d", "e"] Write tests for these cases and make sure your code passes these. Feel free to add any oth necessary

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!