I was wondering what was the most efficient way to rotate a JavaScript array.
I came up with this solution, where a positive n rotates the array to the
n
Native, fast, small, semantic, works on old engines and "curryable".
function rotateArray(offset, array) { offset = -(offset % array.length) | 0 // ensure int return array.slice(offset).concat( array.slice(0, offset) ) }