for self understanding
numbers.reduce(summarize, 0) calculates the sum of all elements in the array.
The summarize callback is invoked for every item in the array with the accumulated sum and the iterated number. summarize callback adds the iterated item to the already accumulated sum, and returns that updated sum.
That's how an array is reducing to a sum.
Also, note the second argument of numbers.reduce(summarize, 0) β the sum of array items is initialized with 0.
What is acc here?
const numList = [1, 3, 55, 22, 44]
function oddAndEvenSumReducer(acc, value) { return acc }
oddAndEvenSumReducer=numList.reduce(oddAndEvenSumReducer)
console.log(oddAndEvenSumReducer)
so here acc is first element in array
Practice exc for useReducer
- Find Even and Odd sum
- Find Even and Odd sum without %2 logic
- Cart managment π(tried useState, then useReducer) SEE HERE