From 79dbdf9b19d17e270ceba357435b0c5a95937a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Wed, 7 Oct 2020 22:42:28 -0500 Subject: [PATCH 1/2] Add Gauss sum or sum of k naturals. --- snippets/gauss-sum.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/gauss-sum.md diff --git a/snippets/gauss-sum.md b/snippets/gauss-sum.md new file mode 100644 index 000000000..1fc59fed8 --- /dev/null +++ b/snippets/gauss-sum.md @@ -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 +``` From ec7fb4fe3f846ceb54faf92dd58f9b1d9b7b8cad Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Thu, 8 Oct 2020 16:52:55 +0300 Subject: [PATCH 2/2] Update and rename gauss-sum.md to sumN.md --- snippets/gauss-sum.md | 17 ----------------- snippets/sumN.md | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 snippets/gauss-sum.md create mode 100644 snippets/sumN.md diff --git a/snippets/gauss-sum.md b/snippets/gauss-sum.md deleted file mode 100644 index 1fc59fed8..000000000 --- a/snippets/gauss-sum.md +++ /dev/null @@ -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 -``` 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 +```