Created
April 16, 2018 23:22
-
-
Save tvler/60bcec963a142c6d9360f6ef5c3b844a to your computer and use it in GitHub Desktop.
Get circular array index
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
const getCircularArrayIndex = (i, { length }) => | |
(i % length + length) % length; | |
const testArray = new Array(5); | |
for (let i = -30; i < 31; i++) { | |
console.log(i, getCircularArrayIndex(i, testArray)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment