title: Passing a math operator as a parameter
body: <p>I'd like to write a function in Javascript that allows me to pass in a mathematical operator and a list of ints and for each item in that list, apply the operator to it. </p>
  
  <p>Thinking of it in terms of a sum, this is what I've come up with:</p>
  
  <pre><code>function accumulate(list, operator){
      var sum = 0;
      for each(var item in list){
          sum = accumulator(sum, item);
      }
      print(sum);
  }
  </code></pre>
  
  <p>Testing this code produces the following error:</p>
  
  <pre><code>var list = new Array();
  list[0] = 1;
  list[1] = 2;
  list[2] = 3;
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>js&gt; accumulate(list, +);
  js: "&lt;stdin&gt;", line 9: syntax error
  js: accumulate(list, +);
  js: ..................^
  js: "&lt;stdin&gt;", line 9: Compilation produced 1 syntax errors.
  </code></pre>