Created
July 17, 2013 13:34
-
-
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.
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
(@currentIndex + 1) % comments.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment