Update and rename gauss-sum.md to sumN.md
This commit is contained in:
committed by
GitHub
parent
79dbdf9b19
commit
ec7fb4fe3f
@ -1,17 +0,0 @@
|
||||
---
|
||||
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
|
||||
```
|
||||
16
snippets/sumN.md
Normal file
16
snippets/sumN.md
Normal 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
|
||||
```
|
||||
Reference in New Issue
Block a user