Array Reduce Flashcards

1
Q

What does Array.reduce do?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What action should the callback function perform?

A

A function to execute for each element in the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What should the callback function return?

A

For the last invocation, the return value becomes the return value of reduce()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Array.reduce useful for?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly