Question: Write a function called unroll, which takes in a square array of arrays (i.e. a grid with n rows and n columns). An input could

 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 and n columns). An input could look like this: const square =[ [1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16] ]; unroll should take in such a square array and return a single array containing the values in the square. You should obtain the values by traversing the square in a spiral: from the top. left corner, move all the way to the right, then 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

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 Databases Questions!