Skip to content

Instantly share code, notes, and snippets.

@martinsson
Created May 1, 2018 22:03
Show Gist options
  • Save martinsson/67ca3b4cb1b611f0674e1d25c325535c to your computer and use it in GitHub Desktop.
Save martinsson/67ca3b4cb1b611f0674e1d25c325535c to your computer and use it in GitHub Desktop.
Bug generator: Use of indices
cardIndex = cardIndex + someStep
if (cardIndex > cards.length) {
cardIndex = 0
}
let card = cards[cardIndex]
// Use of a modulo would be simpler and less error-prone.
cardIndex = (cardIndex + someIndex) % deckOfCards.length
let card = deckOfCards[cardIndex]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment