random-array-iterator
An iterator to iterate an array in random order with controls to requeue or dequeue elements during the iteration.
npm install random-array-iterator
Usage
const RandomArrayIterator =const ite = 1 2 3 4 5for const val of iteconsole // random value// call requeue if you want to revisit this value is the same iterationif someCondition ite// call dequeue if you want to remove the value from the iteration and array entirelyif someOtherCondition ite
API
ite = new RandomArrayIterator(array)
Make a new iterator. Implements the JavaScript iterator interface.
ite.requeue()
Requeue the current value. Only valid to call during an iteration.
ite.dequeue()
Remove the current value from the array and iteration. Only valid to vall during an iteration.
ite.restart()
Restarts the iterator.
License
MIT