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:
cumul = sum.reduce(function (a, n) {
a.push((a.length > 0 ? a[a.length-1] : 0) + n);
return a;
}, [initial]);
cumul.shift();
Logger.log(cumul);
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 <= X, don't add to the cumulative sum in this iteration (show previous cumulative value).
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.
Thanks in advance! G