1

I have a square matrix (might be even or odd nr of items per side) and I wish to rotate it 180 degrees. That is rotate, not flip.

I have found many rotation by 90 degrees of varying shape but no luck finding one for 180 degrees. My matrix could be very large to make doing 2x 90 degree runs unacceptable.

4
  • 2
    Why are you doing this? You just asked a question and answered it yourself. Commented Oct 12, 2013 at 10:13
  • @thefourtheye the website permits Q&A format which I took. You didn't have to downvote everything. Commented Oct 12, 2013 at 15:43
  • I promise. I didnt downvote any of your posts. You can check my profile for my downvotes. Commented Oct 12, 2013 at 16:46
  • You have quelled my thirst of vengeance, for now, @thefourtheye; but I promise you, when I find those response, there will be paint >:) Commented Oct 12, 2013 at 17:25

1 Answer 1

5

Try the following:

grid.reverse().forEach(function(item) { item.reverse(); } );
console.log(grid);
Sign up to request clarification or add additional context in comments.

1 Comment

Or, define reversed(a) as a.slice(0).reverse() and then rotated = reversed(grid).map(reversed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.