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