Created
April 12, 2017 08:08
-
-
Save nash403/c83f88744a352f1cb7c2a9939fe7bb74 to your computer and use it in GitHub Desktop.
Modulo that always returns a value always between 0 and `size - 1`
This file contains hidden or 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
/** | |
* Returns a value always between 0 and size - 1. | |
* @param a current index | |
* @param b size | |
*/ | |
export function modulo(a, b) { return (+a % (b = +b) + b) % b; }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment