Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

rotate matrix 90 degrees clockwise javascript

// transpone
const transpose = matrix => {
  for (let row = 0; row < matrix.length; row++) {
    for (let column = 0; column < row; column++) {
      let temp = matrix[row][column]
      matrix[row][column] = matrix[column][row]
      matrix[column][row] = temp
    }
  }
  return matrix;
}
// reverse 
const reverse = matrix =>  matrix.map(row => row.reverse());
// rotate
const rotate = matrix => transpose(reverse(matrix));
Source by betterprogramming.pub #
 
PREVIOUS NEXT
Tagged: #rotate #matrix #degrees #clockwise #javascript
ADD COMMENT
Topic
Name
6+9 =