Loop with callback with several parameters (and asynchronous calls)
<p>I'm using this pattern for writing loops with callback inside (<a href="http://www.richardrodger.com/2011/04/21/node-js-how-to-write-a-for-loop-with-callbacks/#.VtWyR-MrIo8" rel="nofollow">link</a>).</p>

<pre><code>repeater(i) {
  if( i &lt; length ) {
     asyncwork( function(){
       repeater( i + 1 )
     })
  }
}
repeater(0)
</code></pre>

<p>My problem is that the callback has several parameters and it's ugly to re-write it every time. I report a kind of pseudo code. Inside the 'repeater' there are other asynchronous calls and the code is practically unreadable.</p>

<pre><code>function repeater (index, max, ..., callback) {
  if (index &lt; max) {
    if (index === 1) {
      // Async call to another function
      async () {
        if (index === (max - 1)) {
          callback ();
        } else {
          repeater (++index, max, ..., callback);
        }
      }
    } else if (index === 2) {
      // Async call to another function
      async () {
        if (index === (max - 1)) {
          callback ();
        } else {
          repeater (++index, max, ..., callback);
        }
      }
    }
    // Other cases...
  }
}
</code></pre>

<p>How can I write the code more readable?</p>