

Method arr.reduce explained in the chapter Array methods to get the sum of the array.
Recursive linked list stack code#
Note that the code uses smart features that we’ve covered before:

The information about the process of execution of a running function is stored in its execution context. For that we’ll look under the hood of functions. Now let’s examine how recursive calls work. There are many tasks where recursive way of thinking gives simpler code, easier to maintain. That limits the application of recursion, but it still remains very wide. There are automatic optimizations that help alleviate this (“tail calls optimizations”), but they are not yet supported everywhere and work only in simple cases. We can rely on it being 10000, some engines allow more, but 100000 is probably out of limit for the majority of them. The maximal recursion depth is limited by JavaScript engine. The maximal number of nested calls (including the first one) is called recursion depth.
