The n
parameter is redundant, as it should be possible to deduce the matrix dimensions from matrix
itself, using matrix.length
and matrix[0].length
. You seem to have made the assumption that matrix
is square — you should either document or relax the restriction.
I suggest writing three separate inner functions for the three possible rotations. One code-reuse technique you could use for the ±90° rotations is to combine transpose and row-swap operations transpose and row-swap operations.
The n
parameter is redundant, as it should be possible to deduce the matrix dimensions from matrix
itself, using matrix.length
and matrix[0].length
. You seem to have made the assumption that matrix
is square — you should either document or relax the restriction.
I suggest writing three separate inner functions for the three possible rotations. One code-reuse technique you could use for the ±90° rotations is to combine transpose and row-swap operations.
The n
parameter is redundant, as it should be possible to deduce the matrix dimensions from matrix
itself, using matrix.length
and matrix[0].length
. You seem to have made the assumption that matrix
is square — you should either document or relax the restriction.
I suggest writing three separate inner functions for the three possible rotations. One code-reuse technique you could use for the ±90° rotations is to combine transpose and row-swap operations.
The n
parameter is redundant, as it should be possible to deduce the matrix dimensions from matrix
itself, using matrix.length
and matrix[0].length
. You seem to have made the assumption that matrix
is square — you should either document or relax the restriction.
I suggest writing three separate inner functions for the three possible rotations. One code-reuse technique you could use for the ±90° rotations is to combine transpose and row-swap operations.