Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to rotate a matrix in an array in javascript

function rotate(matrix) {
  return matrix[0].map((col, i) => matrix.map((row) => row[i]))
}

function rotateAntiClockwise(matrix) {
  return matrix[0].map((col, i) => matrix.map((row) => row[i]).reverse())
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #rotate #matrix #array #javascript
ADD COMMENT
Topic
Name
4+2 =