Advertisement
dabidabidesh

rotateArray

Jun 9th, 2020
2,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rotateArray0(arr) {
  2.  
  3.   let arrLength = arr.length
  4.   let s = Number(arr[arrLength - 1])
  5.   let s1 = s % (arrLength - 1)
  6.  
  7.   newArr = []
  8.  
  9.   for (let i = arrLength - s1 - 1, j = 0; i < arrLength - 1; i++, j++)
  10.     newArr[j] = arr[i]
  11.  
  12.   for (let i = 0; i < arrLength - s1 - 1; i++)
  13.     newArr[i + s1] = arr[i]
  14.  
  15.   let output = ''
  16.   for (let i = 0; i < newArr.length; i++)
  17.     output += newArr[i] + ' '
  18.   console.log(output)
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement