358 B
358 B
title, type, language, tags, cover, dateModified
| title | type | language | tags | cover | dateModified | |
|---|---|---|---|---|---|---|
| Sum of numbers until n | snippet | javascript |
|
blue-flower | 2020-10-22T20:24:30+03:00 |
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