It's problems like 5 that make me sad that IE <9 doesn't have Array.prototype.reduce.
return i.reduce(function(prev, next) {
if (typeof(next) == "object" && next.length) { return arraySum(next) + prev; }
if (typeof(next) == "number") { return next + prev; }
return prev;
}, 0);
Something that simple needs to be shimmed on earlier IEs. In fact, I had to look up Array.prototype.reduce for this since I usually use Underscore's. Javascript problems...
Cool project, but all the warnings on that page about the edge cases make me concerned about trying to exuberantly move to ES5, and so I just stick with Underscore and the same level of JavaScript syntax I've been writing since 2005. (sigh)
Pretty interesting solution. The first thing that came to my head was a loop, but you just used reduce. What are some scenarios where you would use a reduce over a loop? I use underscore a lot too, and I find myself just using _.each all the time
Anytime where you are trying to "collect" features of an array into one final value, and the collection function can be sensibly applied to the elements in any order as long as some interim value is passed along (e.g. summing, maximizing), the reduce paradigm is appropriate and can be more readable.
The bonus upside is that these paradigms also make parallelism quite simple, should it later be necessary.