Ivankooo1

rightRotationArray

Aug 31st, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rightRotation(arr,rotation){
  2.     rotation %= arr.length;
  3.  
  4.   while(rotation > 0){
  5.     let lastEl = arr[arr.length-1];
  6.  
  7.     for(let i = arr.length -1; i > 0;i--){
  8.         arr[i] = arr[i - 1];
  9.     }
  10.  
  11.     arr[0] = lastEl;
  12.     rotation--;
  13.   }
  14.  
  15.   console.log(arr.join(', '));
  16. }
  17. rightRotation([1,2,3,4],3);
Advertisement
Add Comment
Please, Sign In to add comment