Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const rotate = (matrix, n) =>{
- for(let layer=0; layer<n; layer++){
- let first =layer;
- let last = n - layer-1;
- for(let i=first; i<last;i++){
- let offset = i-first;
- //save top
- let top = matrix[first][i];
- //left -> top
- matrix[first][i] = [last-offset][first];
- //bottom-left
- matrix[last-offset][first] =matrix[last][last-offset];
- //right to bottom
- matrix[last][last-offset] =matrix[i][last]
- //top - right
- [matrix][i][last] =top;
- }[![enter image description here][1]][1]
- }
- }
- rotate(matrix,3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement