-
-
Save AliceWonderland/08e3e851600a56713b27810c239049bc to your computer and use it in GitHub Desktop.
5.7 Rotate Array created by smillaraaq - https://repl.it/HE2f/3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rotate(myArray, n){ | |
| //num=num % arr.length; //check for if num is greater than length of Array | |
| var begin=-n; | |
| if(n===0){ | |
| return console.log(myArray); | |
| } | |
| console.log(begin); | |
| var spliced=myArray.splice(begin); | |
| return console.log(spliced.concat(myArray)); | |
| } | |
| var myArray = [1, 2, 3, 4, 5] | |
| rotate(myArray, 1) // => [5, 1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment