Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get circular array index
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
You can’t perform that action at this time.