Arrays
Array.prototype.reduce()
Signature
reduce(callbackFn, initialValue?)
Exception
TypeError: throw error if array is empty, AND initialValue is not provided
workflow
- an iterative method
- runs
cbfnover all elements in the array in ascending order - run
cbfn(ans, element) => ansuntil element is null - NOT invoked for empty element
- NOT support
thisArg=undefined, gets substituted withglobalThisif non-strict
Edge case
- default
initialValue = 0