Skip to content

Instantly share code, notes, and snippets.

@GoodBoyNinja
Last active November 17, 2023 22:27
Show Gist options
  • Save GoodBoyNinja/310832f24fb4ae44aa5f6448b2417b35 to your computer and use it in GitHub Desktop.
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