Last active
November 17, 2023 22:27
-
-
Save GoodBoyNinja/310832f24fb4ae44aa5f6448b2417b35 to your computer and use it in GitHub Desktop.
Modulate a number, including negative numbers.
This file contains 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
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