Array Reduce Flashcards
What does Array.reduce do?
user-supplied “reducer” callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element.
What action should the callback function perform?
A function to execute for each element in the array
What should the callback function return?
For the last invocation, the return value becomes the return value of reduce()
What is Array.reduce useful for?
method is an iterative method. It runs a “reducer” callback function over all elements in the array, in ascending-index order, and accumulates them into a single value. Every time, the return value of callbackFn is passed into callbackFn again on next invocation as accumulator
simplification of code