Prepare repository for merge
This commit is contained in:
19
javascript/snippets/sum-n.md
Normal file
19
javascript/snippets/sum-n.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
title: Sum of numbers until n
|
||||
type: snippet
|
||||
tags: [math]
|
||||
cover: blue-flower
|
||||
dateModified: 2020-10-22T20:24:30+03:00
|
||||
---
|
||||
|
||||
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