Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------
- //Write a function that rotates an array.
- //The array should be rotated to the right side, meaning that the last element should become the //first, upon rotation.
- //The input comes as array of strings. The last element of the array is the amount of rotation you need to perform.
- //The output is the resulted array after the rotations. The elements should be printed on one line, separated by a single space.
- //------------------------------------------------------
- function rotate_Array(array) {
- let arr = array;
- let rotations = arr.pop()
- for (i = 0; i < rotations; i++) {
- let lastEl = arr.pop()
- arr.unshift(lastEl)
- }
- console.log(arr.join(' '))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement