Skip to content

Instantly share code, notes, and snippets.

@slikts
Last active August 29, 2015 13:57
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 slikts/9586671 to your computer and use it in GitHub Desktop.
Save slikts/9586671 to your computer and use it in GitHub Desktop.
// array-like only
function get(arr, i) {
var len = arr.length;
i = i % len;
if (i < 0) {
i += len;
}
return arr[i];
}
// get([0,1,2], -1) = 2
// get([0,1,2], -2) = 1
// get([0,1,2], 3) = 0
// get([0,1,2], 4) = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment