borisova936935

Untitled

Jan 28th, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function arrayRotation(list, rotations) {
  2.     for (let i = 0; i < rotations; i++) {
  3.         let firstElement = list[0];
  4.         for (let j = 0; j < list.length - 1; j++) {
  5.             list[j] = list[j + 1];
  6.         }
  7.         let lastIndex = list.length - 1;
  8.         list[lastIndex] = firstElement;
  9.     }
  10.     console.log(list.join(" "));
  11. }
Advertisement
Add Comment
Please, Sign In to add comment