Skip to content

Instantly share code, notes, and snippets.

@davedx
Created December 10, 2013 14:38
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 davedx/7891611 to your computer and use it in GitHub Desktop.
Save davedx/7891611 to your computer and use it in GitHub Desktop.
// cycle through "myArray" in "dir" (-1 or +1), wrapping around
var nextIdx = (currentIdx + dir) % myArray.length;
if(nextIdx < 0) nextIdx = myArray.length - 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment