1// syntax: array.reduce(function, accumulator-initial-value)
2let array = [3, 7, 2, 9, 5]
3const result = array.reduce((accumulator, currentValue, currentIndex, arr) => {
4 // code
5}, initialValue)
6
7// accumulator = will store return value of the function
8// currentValue = iterate through each array element
9// currentIndex = index of currentValue
10// arr = original array
11// initialValue = set accumulator initial value
1const list = [1, 2, 3, 4, 5];
2console.log(list.reduce((number, nextNumber) => number + nextNumber));
3// --> 15