Skip to content

Instantly share code, notes, and snippets.

@bflannery
Created January 19, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bflannery/caa075a4a28236cd44cc97d58c0ffaeb to your computer and use it in GitHub Desktop.
Save bflannery/caa075a4a28236cd44cc97d58c0ffaeb to your computer and use it in GitHub Desktop.
Rotate the array (first arg) left n (second arg) amount of times
// Rotate the array (first arg) left n (second arg) amount of times
function arrRotate(arr, n) {
let i = 0;
let result = arr.map(function() {
return arr[ (i++ + n) % arr.length ];
});
console.log(result.join(" "));
}
arrRotate([1,2,3,4,5],4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment