title: How do I write my own `reduce` function?
body: <p>I want write <code>reduce</code> by myself. But over the last 4 hours, I couldn't.</p>
  
  <pre><code>var a = [10, 21, 13, 56];
  
  function add(a, b) { return a + b }
  function foo(a, b) { return a.concat(b) }
  
  Array.prototype.reduce2 = function () {
    // I do not understand how to handle the function of the inlet
    // I know that I should use arguments, but I don't know how many arguments there will be
    var result = 0;
    for(var i = 0; i &lt; arguments.length; i++) {
      result += arguments[i];
    }
   return result;
  };
  
  console.log(a.reduce(add), a.reduce2(add))         // 100 100
  console.log(a.reduce(add, 10), a.reduce2(add, 10)) // 110 110
  </code></pre>
  
  <p>Yes, I know that this seems like a lot of topics, but I couldn't find answer.  What am I missing, or doing wrong here?</p>