Skip to content

Instantly share code, notes, and snippets.

@jktravis
Created February 20, 2020 20:08
Show Gist options
  • Save jktravis/8a36b65dba9ab85472140461e036f0c0 to your computer and use it in GitHub Desktop.
Save jktravis/8a36b65dba9ab85472140461e036f0c0 to your computer and use it in GitHub Desktop.
A function to wrap numbers around
// 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