Efficient way to circle through an array?
<p>I'm wondering if there is a more effective way of circling through an array. For my purposes, the array is holding image sources. When the last image is shown and the next button is pushed it circles back to the first image. If the previous button is pushed on the first image it circles to the last image.</p>

<p>This is what I was able to come up with, but I feel there's a more efficient way to go about it.</p>

<pre><code>var marker = 0;

// Circle through an array.
function moveMarker(array, action, direction) {
    if (!direction) {
        if(marker == array.length - 1)
            marker = -1;
        marker += 1;
        action();
    }

    else {
        if (marker == 0)
            marker = array.length;
        marker -=1;
        action();
    }
}
</code></pre>
