src/utilities/Iterator.js
function Iterator(array) {

    // the array and current slot index are private attributes so methods that use them
    // are defined in the constructor
    var currentSlot = 0;  // the slot before the first item

    this.toStart = function() {
        currentSlot = 0;  // the slot before the first item
    };

    this.toSlot = function(slot) {
        const size = array.length;
        if (slot > size) slot = size;
        if (slot < -size) slot = -size;
        if (slot < 0) slot = slot + size + 1;
        currentSlot = slot;
    };

    this.toEnd = function() {
        currentSlot = array.length;  // the slot after the last item
    };

    this.hasPrevious = function() {
        return currentSlot > 0;
    };

    this.hasNext = function() {
        return currentSlot < array.length;
    };

    this.getPrevious = function() {
        if (!this.hasPrevious()) return;
        return array[--currentSlot];
    };

    this.getNext = function() {
        if (!this.hasNext()) return;
        return array[currentSlot++];
    };

    return this;
}
function Iterator(array) {

    // the array and current slot index are private attributes so methods that use them
    // are defined in the constructor
    var currentSlot = 0;  // the slot before the first item

    this.toStart = function() {
        currentSlot = 0;  // the slot before the first item
    };

    this.toSlot = function(slot) {
        const size = array.length;
        if (slot > size) slot = size;
        if (slot < -size) slot = -size;
        if (slot < 0) slot = slot + size + 1;
        currentSlot = slot;
    };

    this.toEnd = function() {
        currentSlot = array.length;  // the slot after the last item
    };

    this.hasPrevious = function() {
        return currentSlot > 0;
    };

    this.hasNext = function() {
        return currentSlot < array.length;
    };

    this.getPrevious = function() {
        if (!this.hasPrevious()) return;
        return array[--currentSlot];
    };

    this.getNext = function() {
        if (!this.hasNext()) return;
        return array[currentSlot++];
    };

    return this;
}
function Iterator ( array ) { // the array and current slot index are private attributes so methods that use them // are defined in the constructor var currentSlot = 0 ; // the slot before the first item this . toStart = function ( ) { currentSlot = 0 ; // the slot before the first item } ; this . toSlot = function ( slot ) { const size = array . length ; if ( slot > size ) slot = size ; if ( slot < - size ) slot = - size ; if ( slot < 0 ) slot = slot + size + 1 ; currentSlot = slot ; } ; this . toEnd = function ( ) { currentSlot = array . length ; // the slot after the last item } ; this . hasPrevious = function ( ) { return currentSlot > 0 ; } ; this . hasNext = function ( ) { return currentSlot < array . length ; } ; this . getPrevious = function ( ) { if ( ! this . hasPrevious ( ) ) return ; return array [ -- currentSlot ] ; } ; this . getNext = function ( ) { if ( ! this . hasNext ( ) ) return ; return array [ currentSlot ++ ] ; } ; return this ; }
PUBLIC CONSTRUCTORS 
This constructor creates a new array iterator that allows the items in the array
to be iterated over in either direction.

@constructor
@param {Array} array The array to be iterated over.
@returns {Iterator} The new array iterator.
PUBLIC CONSTRUCTORS This constructor creates a new array iterator that allows the items in the array to be iterated over in either direction .