title: Optional parameter in Javascript reduce function
body: <p>I'm working on writing a reduce function in Javascript. The function works correctly when no argument for start(the counter) is passed, but when a start value is passed, I get an incorrect answer. For example, if I pass      <code>([1,2,3], function(a,b){return a + b;}, 0)</code> to the function, it outputs 5 instead of 6. If no third argument(start value) is passed, I want the "total" variable to be set to the first element in the array using shift, so that element is then removed and not counted again.</p>
  
  <pre><code>function reduce(arr, func, start) {
      var total = start || arr.shift();
      each(arr, function(item) {
          total = func(item, total);
      });
      return total;
  };
  </code></pre>
  
  <p>(Each is a simple forEach function I wrote, that works fine.) I've tried a ton of different variations, and I can't seem to get this to work. Is there a better way set the total variable when no third argument is passed? </p>