title: Cumulative sum of array, with condition in another array
body: <p>I need to perform a cumulative sum of an array. Under certain conditions, I need it to be straight forward, and found this snippet to work great:</p>
  
  <pre><code>cumul = sum.reduce(function (a, n) { 
                         a.push((a.length &gt; 0 ? a[a.length-1] : 0) + n); 
                         return a;
                     }, [initial]);
  cumul.shift();
  Logger.log(cumul);
  </code></pre>
  
  <p>When I log 'cumul' I get the result I need. However, under other IF() conditions, I need to perform the cumulative sum providing a certain condition in another array containing dates is met - if the date is &lt;= X, don't add to the cumulative sum in this iteration (show previous cumulative value).</p>
  
  <p>Any ideas how to implement this? It seems that using this version of a cumulative sum won't work, but I'm not sure what would be other ways to go about this. </p>
  
  <p>Thanks in advance!
  G</p>