Creates a generator to step through array indices.
Supports moving forward/backward through an array, looping, 'drunken walk', and random step lengths.
constdata [ `a`, `b`, `c`, `d`, `e` ];
// Step one by one through each index for (const index of arrayIndexStepper({step:1, loop:`none`}, data)) { console.log(`index: ${index} value: ${data[index]}`); }
More examples:
// A generator that never ends, going back and forth between start and end arrayIndexStepper({ steps:1, loop:`pingpong` }, data); // As above, but when we hit the end/start, repeat that index arrayIndexStepper({ steps:1, loop:`pingpong`, repeatLoopedIndex:true }, data);
// Move backwards. from the end, through the indicies, jumping by two arrayIndexStepper({ steps:2, forward:false }, data);
Creates a generator to step through array indices.
Supports moving forward/backward through an array, looping, 'drunken walk', and random step lengths.
More examples: