I had resolved this for you, I will show you my test case... and then i will show you what i did to adjust it for you.
var len = 6;
for (var i = 0; i < 100; i++){
console.log("value:", Number(i%len));
}
this shows just a loop, iterating over something of size 6, and resetting it back to 0, a continual loop forward. Similarly, in the other direction.
var len = 6;
for (var i = 100; i >= 0; i--){
console.log("value:", Number(i%len));
}
So you can sort of get mod to work forward. for reverse, -1 would not mod with len to loop back to the end, so you could say:
var len = this._length;
newIndex%=len;
if(newIndex < 0){
newIndex = len;
}
if there is an issue with len
, then it means there is an issue with this._length
which you defined. You need to make sure you understand that when there is an array of items, say: 6.... their indices are actually 0 through 5.
That could be a secondary issue as per your question.