January 2020
Intermediate to advanced
470 pages
11h 13m
English
The notion is also extended to internal variables, in which a local state is stored and then used for future calls. In this case, the external state is unchanged, but there are side effects that imply future differences as to the returned values from the function. Let's imagine a roundFix() rounding function that takes into account whether it has been rounding up or down too much so that the next time, it will round the other way, bringing the accumulated difference closer to zero. Our function will have to accumulate the effects of previous roundings to decide how to proceed next. The implementation could be as follows:
const roundFix = (function() { let accum = 0; return n => { // reals get rounded up or down // depending on ...