Skip to content

Instantly share code, notes, and snippets.

@blacksheep557
Created June 5, 2020 04:04
Show Gist options
  • Select an option

  • Save blacksheep557/967028715d3e5d9df571177c989112bb to your computer and use it in GitHub Desktop.

Select an option

Save blacksheep557/967028715d3e5d9df571177c989112bb to your computer and use it in GitHub Desktop.
function rotateImage(imageMatrix = [[]]) {
//transpose the matrix
for (let row = 0; row < imageMatrix.length; row++) {
for (let col = row + 1; col < imageMatrix[0].length; col++) {
let temp = imageMatrix[row][col];
imageMatrix[row][col] = imageMatrix[col][row];
imageMatrix[col][row] = temp;
}
}
// return each row reversed
return imageMatrix.map((row) => row.reverse());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment