DEV Community

Cover image for A silly way to reverse an array
Matt Ellen
Matt Ellen

Posted on

A silly way to reverse an array

I was looking at a post in the challenge tag today, and it got me looking into polar coordinates, and I saw that you can rotate an array by 180 degrees by putting a pole in the middle and spinning the array around it, so here it is:

The only issue I have is that small arrays seem to get a load of gaps at the beginning that I needed to filter out. Not sure why that is.

Top comments (1)

Collapse
 
mellen profile image
Matt Ellen • Edited

I see the problem. I'm creating a square grid, and if the array's length is not a perfect square, then there will be blanks in the grid, which get rotated with the items.