Add Gauss sum or sum of k naturals.

This commit is contained in:
Juan José Arboleda
2020-10-07 22:42:28 -05:00
parent 7f95bbb8f3
commit 79dbdf9b19

17
snippets/gauss-sum.md Normal file
View File

@ -0,0 +1,17 @@
---
title: gauss-sum
tags: math,beginner
---
Sums the numbers between 1 up to `limit` argument.
- It is an implementation of the Gauss sum equation.
```js
const gaussSum = limit =>
(limit * (limit + 1)) / 2;
```
```js
gaussSum(100); // 1 + 2 + 3 + 4 + ... + 100 = 5050
```