Merge pull request #1419 from juanarbol/juanarbol/add-gauss-sum-alg

Add Gauss sum or sum of k naturals.
This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-08 16:53:14 +03:00
committed by GitHub

16
snippets/sumN.md Normal file
View File

@ -0,0 +1,16 @@
---
title: sumN
tags: math,beginner
---
Sums all the numbers between 1 and `n`.
- Use the formula `(n * (n + 1)) / 2` to get the sum of all the numbers between 1 and `n`.
```js
const sumN = n => (n * (n + 1)) / 2;
```
```js
sumN(100); // 5050
```