sumN
Sums all the numbers between 1 and n.
- Use the formula
(n * (n + 1)) / 2to get the sum of all the numbers between 1 andn.
const sumN = n => (n * (n + 1)) / 2;sumN(100); // 5050
Sums all the numbers between 1 and n.
(n * (n + 1)) / 2 to get the sum of all the numbers between 1 and n.const sumN = n => (n * (n + 1)) / 2;sumN(100); // 5050