Created
April 12, 2017 05:30
-
-
Save anonymous/73be4a82c969d7b6b4f1f6bfdd703f04 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