Ivankooo1

leftRotationArray

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