Skip to content

Instantly share code, notes, and snippets.

Created April 12, 2017 05:30
Show Gist options
  • Select an option

  • Save anonymous/73be4a82c969d7b6b4f1f6bfdd703f04 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/73be4a82c969d7b6b4f1f6bfdd703f04 to your computer and use it in GitHub Desktop.
5.7 Rotate Array created by smillaraaq - https://repl.it/HE2f/3
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