Skip to content

Instantly share code, notes, and snippets.

@nash403
Created April 12, 2017 08:08
Show Gist options
  • Save nash403/c83f88744a352f1cb7c2a9939fe7bb74 to your computer and use it in GitHub Desktop.
Save nash403/c83f88744a352f1cb7c2a9939fe7bb74 to your computer and use it in GitHub Desktop.
Modulo that always returns a value always between 0 and `size - 1`
/**
* 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