17 lines
253 B
Markdown
17 lines
253 B
Markdown
---
|
|
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
|
|
```
|