How is this array join producing strings of characters?
<p>A problem over at CodeWars is to write a function, <code>accum(s)</code>, that does the following:</p>

<pre><code>accum("abcd");    // "A-Bb-Ccc-Dddd"
accum("RqaEzty"); // "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt");    // "C-Ww-Aaa-Tttt"
</code></pre>

<p>An answer to this problem is the following:</p>

<pre><code>function accum(s) {
  return s.split('').map((x,index) =&gt; x.toUpperCase()+Array(index+1).join(x.toLowerCase())).join('-');
}
</code></pre>

<p>I am particularly interested in what <code>x.toUpperCase()+Array(index+1).join(x.toLowerCase())</code> does.</p>

<p>If I write it in pieces, <code>Array</code> outputs <code>[]</code>. <code>Array(1)</code> outputs <code>[ ]</code>. <code>Array(2)</code> outputs <code>[ ,  ]</code>. That's seems... odd.</p>

<p>Even stranger, <code>'a' + Array()</code> outputs <code>a</code>, <code>'a' + Array(1)</code> seemingly outputs <code>a</code> as well, <code>'a' + Array(2)</code> outputs <code>a,</code>, <code>'a' + Array(3)</code> outputs <code>a,,</code>. Notice that the angular brackets are gone. I.e., it is not an array. Again, that seems... odd.</p>

<p>Even better, <code>'a' + Array() + 'b'</code> outputs <code>a</code>, <code>'a' + Array(1) + 'b'</code> outputs <code>a</code>, <code>'a' + Array(2) + 'b'</code> outputs <code>ab</code>.</p>

<p>My question is if someone could explain what is happening exactly in all these three cases. In the first case, why does there seem to be a space added going from <code>Array()</code> to <code>Array(1)</code>? And why does <code>Array(2)</code> not output <code>[,]</code>, but <code>[ ,  ]</code>?</p>

<p>And what happens when a letter is concatenated with <code>Array(n)</code>? What is returned by <code>Array(n)</code> in this case?</p>