Skip to content

Instantly share code, notes, and snippets.

@austinbv
Created June 8, 2012 02:34
Show Gist options
  • Save austinbv/2893171 to your computer and use it in GitHub Desktop.
Save austinbv/2893171 to your computer and use it in GitHub Desktop.
_.rotate = function(array, count) {
var array = _.clone(array),
count = count || 1;
if (Math.abs(count) > array.length/2) count = 0 - count;
if (count < 0)
while (count++) array.unshift(array.pop());
else
while (count--) array.push(array.shift());
return array;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment