diff --git a/snippets/sumN.md b/snippets/sumN.md new file mode 100644 index 000000000..55e1fb868 --- /dev/null +++ b/snippets/sumN.md @@ -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 +```