Understanding in-place mergesort
<p>I'm struggling to understand the in-place version of merge sort. </p>

<pre><code>function merge(left, right){
    var result  = [],
        il      = 0,
        ir      = 0;

    while (il &lt; left.length &amp;#038;&amp;#038; ir &lt; right.length){
        if (left[il] &lt; right[ir]){
            result.push(left[il++]);
        } else {
            result.push(right[ir++]);
        }
    }

    return result.concat(left.slice(il)).concat(right.slice(ir));
}


function mergeSort(items){

    if (items.length &lt; 2) {
        return items;
    }

    var middle = Math.floor(items.length / 2),
        left    = items.slice(0, middle),
        right   = items.slice(middle),
        params = merge(mergeSort(left), mergeSort(right));

    params.unshift(0, items.length);
    items.splice.apply(items, params);
    return items;
}
</code></pre>

<p>What is the purpose of adding <code>0</code> and <code>items.length</code> to the front of params? I don't understand what <code>items.splice.apply</code> is doing, but from console logging some examples, it looks like it just removes what was unshifted on to <code>params</code>. What is the reason for this?</p>