Created
March 20, 2019 23:37
-
-
Save mikehazell/4cf8da0ce3241f11ccdafa54b1c6b083 to your computer and use it in GitHub Desktop.
This file contains 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
// Get the next or previous index in an array | |
// and loop around if you exede the bounds. | |
// Found this in a Ryan Florence Video. Kept coming back | |
// to it so though I'd put it somewhere easier to find. | |
// Video here: https://youtu.be/wXLf18DsV-I?t=769 | |
const nextIndex = (currentIndex, length) => ( | |
(currentIndex + 1 + length) % length | |
); | |
const previousIndex = (currentIndex, length) => ( | |
(currentIndex - 1 + length) % length | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment