Created
January 19, 2017 17:03
-
-
Save bflannery/caa075a4a28236cd44cc97d58c0ffaeb to your computer and use it in GitHub Desktop.
Rotate the array (first arg) left n (second arg) amount of times
This file contains 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
// 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