Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. const rotate = (matrix, n) =>{
  2. for(let layer=0; layer<n; layer++){
  3. let first =layer;
  4. let last = n - layer-1;
  5. for(let i=first; i<last;i++){
  6.  
  7. let offset = i-first;
  8. //save top
  9. let top = matrix[first][i];
  10. //left -> top
  11. matrix[first][i] = [last-offset][first];
  12. //bottom-left
  13. matrix[last-offset][first] =matrix[last][last-offset];
  14. //right to bottom
  15. matrix[last][last-offset] =matrix[i][last]
  16.  
  17. //top - right
  18. [matrix][i][last] =top;
  19.  
  20.  
  21. }[![enter image description here][1]][1]
  22. }
  23. }
  24.  
  25. rotate(matrix,3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement