Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Created September 11, 2017 18:04
Show Gist options
  • Save ayamflow/6ba2cb1a7b18f8e5c835f3b651107100 to your computer and use it in GitHub Desktop.
Save ayamflow/6ba2cb1a7b18f8e5c835f3b651107100 to your computer and use it in GitHub Desktop.
Loop numbers between min/max using the modulo operator
function loop(val, min, max) {
return ((val - min) % (max - min + 1) + (max - min + 1)) % (max - min + 1) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment