Advertisement
Guest User

Untitled

a guest
Jan 28th, 2022
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rotation(arr, rotations) {
  2.     let rotationsExcecuted = 0;
  3.     let lastItem = ``;
  4.    
  5.     while (rotations > rotationsExcecuted) {
  6.         let newArr = [];
  7.         lastItem = arr[0]
  8.         for (let i = 0; i < arr.length-1; i++) {
  9.             newArr.push(arr[i + 1])
  10.         }
  11.         newArr.push(lastItem)
  12.         rotationsExcecuted++;
  13.         arr = newArr;
  14.     }
  15.  
  16.     console.log(arr.join(` `));
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement