Skip to content

Instantly share code, notes, and snippets.

@brigand
Created June 7, 2021 01:19
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 brigand/e537a37b0a7c6e6fe2a7b5ac6c69b4f2 to your computer and use it in GitHub Desktop.
Save brigand/e537a37b0a7c6e6fe2a7b5ac6c69b4f2 to your computer and use it in GitHub Desktop.
const get = (array, currentKey, direction) => {
const k = currentKey ? currentKey : array[0];
const delta = direction == 'inc' ? 1 : -1
const index = array.indexOf(k);
const nextIndex = (index + delta + array.length) % array.length;
console.log(array[nextIndex]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment