Skip to content

Instantly share code, notes, and snippets.

@jondashkyle
Last active November 17, 2020 17:23
Show Gist options
  • Save jondashkyle/243b7c459fab609d9e960bf99d08c7d1 to your computer and use it in GitHub Desktop.
Save jondashkyle/243b7c459fab609d9e960bf99d08c7d1 to your computer and use it in GitHub Desktop.
Slideshow previous and next mod operator
/**
* 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