DEV Community

Discussion on: Daily Challenge #5 - Ten Minute Walk

Collapse
 
johncip profile image
jmc

For wrapping some sum x + y inside of a range n, you can use (x + y) % n (and of course bounds-checking with if works too).

N.B. different languages treat negative mod differently. For JS, in the negative case you'd want something like ((x % n) + n) % n instead of plain %.