Skip to content

Instantly share code, notes, and snippets.

@GoodBoyNinja
Last active November 17, 2023 22:27
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save GoodBoyNinja/310832f24fb4ae44aa5f6448b2417b35 to your computer and use it in GitHub Desktop.
Modulate a number, including negative numbers.
function ModNum (n, m) {
try {
if (n >= m || n <= 0) {
return ((n % m) + m) % m;
} else {
return n;
}
} catch (e) {
// maybe print or alert an error
return n;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment