javascript function calculate sum code example
Example 1: sum all elements in array javascript
arr.reduce((a, b) => a + b)
Example 2: summation js
const summation = (n) => (n * (n + 1)) / 2;
arr.reduce((a, b) => a + b)
const summation = (n) => (n * (n + 1)) / 2;