Skip to content

Instantly share code, notes, and snippets.

@hellerve
Created January 5, 2016 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellerve/be15db7d66edcd147ff5 to your computer and use it in GitHub Desktop.
Save hellerve/be15db7d66edcd147ff5 to your computer and use it in GitHub Desktop.
A next() and previous() method for arrays with builtin wraparound
Array.prototype.next = function(i) {
return this[++i % this.length];
}
Array.prototype.previous = function(i) {
return i === 0 ? this[this.length - 1] : this[--i % this.length];
}
@disarticulate
Copy link

coo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment