User Tools

Site Tools


java-script:reduce:summing-numbers

Summing numbers using reduce

summing-numbers-reduce.js
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, 0);
 
console.log(sum); // Output: 15
java-script/reduce/summing-numbers.txt · Last modified: 2023/08/07 20:49 by odefta