var numbersArary = [2,5,6]; var newResultValue = numbersArary.reduce(testFunc,0) function testFunc(accumulator,number) { return accumulator + number; } console.log(newResultValue); //Output : 13
const numbersArary = [2,5,6]; const reducer = (accumulator, currentValue) => accumulator + currentValue; // 2 + 5 + 6 console.log(numbersArary.reduce(reducer)); // Output : 13 // 3 + 2 + 5 + 6 console.log(numbersArary.reduce(reducer, 3)); // expected output: 16
Related
JavaScript Average Program using Arrow Function