Rotate Matrix 90

Rotate a 2D square matrix 90 degrees clockwise by transposing and reversing rows.

Code

General
matrix[0].map((_, i) => matrix.map(row => row[i]).reverse());

Parameters

Square matrix

Browser·fetch() may be limited by CORS

More JavaScript Snippets