Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function leftRotation(arr,rotation){
- rotation %= arr.length;
- while(rotation > 0){
- let firstEl = arr[0];
- for(let i = 0;i < arr.length;i++){
- arr[i] = arr[i + 1];
- }
- arr[arr.length-1] = firstEl;
- rotation--;
- }
- console.log(arr.join(', '));
- }
- leftRotation([1,2,3,4],3);
Advertisement
Add Comment
Please, Sign In to add comment