Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Last active December 9, 2017 20:18
Show Gist options
  • Select an option

  • Save paulhayes/c47930054e82dd5b12965e9064835c3f to your computer and use it in GitHub Desktop.

Select an option

Save paulhayes/c47930054e82dd5b12965e9064835c3f to your computer and use it in GitHub Desktop.
Using modulo operating to wrap values in both positive and negative directions
Number.prototype.wrap = function(len){return ((this.valueOf()%len)+len)%len; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment