-
-
Save brigand/e537a37b0a7c6e6fe2a7b5ac6c69b4f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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