Skip to content

Instantly share code, notes, and snippets.

@TracyGJG
Created August 16, 2025 10:57
Show Gist options
  • Select an option

  • Save TracyGJG/1f1cd852efc960398082864215c9656e to your computer and use it in GitHub Desktop.

Select an option

Save TracyGJG/1f1cd852efc960398082864215c9656e to your computer and use it in GitHub Desktop.
Modulo that handles negative values properly
function modulo(mod, val) {
return val == null ? (_val) => _mod(mod, _val) : _mod(mod, val);
function _mod(mod, val) {
return (val + mod) % mod;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment