Created
February 20, 2020 20:08
-
-
Save jktravis/8a36b65dba9ab85472140461e036f0c0 to your computer and use it in GitHub Desktop.
A function to wrap numbers around
This file contains hidden or 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
// I found this somewhere, but cannot remember where. | |
// feel free to leave a comment if you'd like to claim it. | |
const wrap = function(min, max, v) { | |
const rangeSize = max - min; | |
return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment