Last active
November 17, 2020 17:23
-
-
Save jondashkyle/243b7c459fab609d9e960bf99d08c7d1 to your computer and use it in GitHub Desktop.
Slideshow previous and next mod operator
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
/** | |
* For some reason I'm always forgetting this. | |
* Probably because I'm not a mathematician. | |
*/ | |
let counter = 0 | |
const prev () => { | |
counter -= 1 | |
} | |
const next () => { | |
counter += 1 | |
} | |
const slide = () => { | |
let index = mod(counter, slides.length) | |
return slide = slides[index] | |
} | |
const mod = (num, mod) => { | |
let remain = num % mod | |
return Math.floor(remain >= 0 ? remain : remain + mod) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment