Skip to content

Instantly share code, notes, and snippets.

@brooksgarrett
Created July 17, 2013 13:34
Show Gist options
  • Save brooksgarrett/6020594 to your computer and use it in GitHub Desktop.
Save brooksgarrett/6020594 to your computer and use it in GitHub Desktop.
I came across this today and it provides a pretty slick way of looping an array by index without running out of bounds. With array length of 3::: 1 mod 3 is 1; 2 mod 3 is 2; 3 mod 3 is 0; 4 mod 3 is 1; This is not my creation. I'm sure it is fairly standard but I saw it first in the Comments widget from the Dashing Dashboard.
(@currentIndex + 1) % comments.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment