How to implement carousel with an array
<p>I have an array of items representing a virtual carousel.</p>

<pre><code>const carousel = ['a','b','c','d','e'];
let currentIndex = 0;

function move (amount) {
   const l = items.length;  // in case carousel size changes

   // need to update currentIndex

   return carousel[currentIndex];

}
</code></pre>

<p>What is a clean or clever way to handle moving left when <code>currentIndex == 0</code> and moving right when <code>currentIndex == length-1</code>?</p>

<p>I have thought about this before and have never come with anything very clever or concise.</p>