Skip to content

Instantly share code, notes, and snippets.

@aarongeorge
Created January 28, 2016 03:09
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 aarongeorge/e221f8283560e336e95a to your computer and use it in GitHub Desktop.
Save aarongeorge/e221f8283560e336e95a to your computer and use it in GitHub Desktop.
Cyclic Array Index
var arr = ['a', 'b', 'c'];
var cyclicArray = function (arr, index) {
var item = ((index % arr.length) + arr.length) % arr.length;
console.log(arr[item], item);
}
for (var i = -5; i < 5; i++) {
cyclicArray(arr, i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment