The use of first last and map to implement Reduce
<p>I stumbled upon this code that is meant to redefine Array.prototype.reduce: </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function first(array, n){
  return n === undefined ? array[0] : array.slice(0, n);
}; 

function last(array, n){
  if(n&gt; array.length){
    return array;
    }else{
      return n === undefined ? array[array.legnth -1] : array.slice(array.length - n, array.length);
      
};
  
  function map(collection, iterator){
    var arr = []; 
    each(collection, function(element, index){
      arr.push(iterator(element, index);
    });
     return arr;
  };</code></pre>
</div>
</div>
</p>

<pre class="lang-js prettyprint-override"><code>function reduce(collection, rf, acc) {
    acc = acc === undefined ? first(collection) : acc;
    return last(map(collection, function (value) {
        acc = rf(acc, value);
        return acc;
    }));
}
</code></pre>

<p>However, I don't understand what array.last() is doing here. Can someone please explain. Thank you. </p>