From 7039da5b8c79cb6d80c2b6aa917212bea90c2cbb Mon Sep 17 00:00:00 2001 From: Rohit Tanwar Date: Mon, 1 Jan 2018 16:26:38 +0530 Subject: [PATCH 1/7] add mask --- snippets/mask.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 snippets/mask.md diff --git a/snippets/mask.md b/snippets/mask.md new file mode 100644 index 000000000..e69de29bb From 572d1938c74e0ee9015199504e5a5d8e106aa9c8 Mon Sep 17 00:00:00 2001 From: Rohit Tanwar Date: Mon, 1 Jan 2018 19:19:25 +0530 Subject: [PATCH 2/7] add sumPower --- snippets/sumPower.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 snippets/sumPower.md diff --git a/snippets/sumPower.md b/snippets/sumPower.md new file mode 100644 index 000000000..d0f58c2a7 --- /dev/null +++ b/snippets/sumPower.md @@ -0,0 +1,15 @@ +### sumPower + +Returns the sum of the powers of all the numbers from `start`(default to 1) to `end` + +```js +const sumPower = (end,power = 2,start = 1) + Array(end - start).fill(0).map((x,i) => (i+start) ** power).reduce((a,b) => a+b,0) +``` + +```js +sumPower(10); // 385 +sumPower(10,3); //3025 +sumPower(10,3,5); //2925 +sumPower(10,undefined,5); //355 +``` From dc85517cfd46e2d5fa0db00419ddd82ace1b21c1 Mon Sep 17 00:00:00 2001 From: Rohit Tanwar Date: Mon, 1 Jan 2018 19:21:54 +0530 Subject: [PATCH 3/7] update tag_database --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index 54667d9c4..9d64ea1b5 100644 --- a/tag_database +++ b/tag_database @@ -140,6 +140,7 @@ splitLines:string spreadOver:adapter standardDeviation:math sum:math +sumPower:math symmetricDifference:array tail:array take:array From f273c0c2f8715b494ff0473c87e224ccf68915cc Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 1 Jan 2018 16:21:03 +0200 Subject: [PATCH 4/7] Update sumPower.md --- snippets/sumPower.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/snippets/sumPower.md b/snippets/sumPower.md index d0f58c2a7..846989089 100644 --- a/snippets/sumPower.md +++ b/snippets/sumPower.md @@ -1,6 +1,10 @@ ### sumPower -Returns the sum of the powers of all the numbers from `start`(default to 1) to `end` +Returns the sum of the powers of all the numbers from `start` to `end`. + +Use `Array.fill()` to create an array of all the numbers in the target range, `Array.map()` and the exponent operator (`**`) to raise them to `power` and `Array.reduce()` to add them together. +Omit the second argument, `power`, to use a default power of `2`. +Omit the third argument, `start`, to use a default starting value of `1`. ```js const sumPower = (end,power = 2,start = 1) From b380a01c8f2b6490d4e460e26110e1d82fbf5993 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 1 Jan 2018 16:22:06 +0200 Subject: [PATCH 5/7] Update sumPower.md --- snippets/sumPower.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/sumPower.md b/snippets/sumPower.md index 846989089..7721c3747 100644 --- a/snippets/sumPower.md +++ b/snippets/sumPower.md @@ -7,7 +7,7 @@ Omit the second argument, `power`, to use a default power of `2`. Omit the third argument, `start`, to use a default starting value of `1`. ```js -const sumPower = (end,power = 2,start = 1) +const sumPower = (end,power = 2,start = 1) => Array(end - start).fill(0).map((x,i) => (i+start) ** power).reduce((a,b) => a+b,0) ``` From 1b229a78bf1640e85046146772616c25e73d1930 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 1 Jan 2018 16:23:58 +0200 Subject: [PATCH 6/7] Update sumPower.md --- snippets/sumPower.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/sumPower.md b/snippets/sumPower.md index 7721c3747..27c4d5130 100644 --- a/snippets/sumPower.md +++ b/snippets/sumPower.md @@ -1,6 +1,6 @@ ### sumPower -Returns the sum of the powers of all the numbers from `start` to `end`. +Returns the sum of the powers of all the numbers from `start` to `end` (both inclusive). Use `Array.fill()` to create an array of all the numbers in the target range, `Array.map()` and the exponent operator (`**`) to raise them to `power` and `Array.reduce()` to add them together. Omit the second argument, `power`, to use a default power of `2`. @@ -8,7 +8,7 @@ Omit the third argument, `start`, to use a default starting value of `1`. ```js const sumPower = (end,power = 2,start = 1) => - Array(end - start).fill(0).map((x,i) => (i+start) ** power).reduce((a,b) => a+b,0) + Array(end + 1 - start).fill(0).map((x,i) => (i+start) ** power).reduce((a,b) => a+b,0) ``` ```js From 8a360fc8ffbec8999fc9b6386c1beb4323a198e3 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 1 Jan 2018 16:24:54 +0200 Subject: [PATCH 7/7] Update sumPower.md --- snippets/sumPower.md | 1 - 1 file changed, 1 deletion(-) diff --git a/snippets/sumPower.md b/snippets/sumPower.md index 27c4d5130..763917f0a 100644 --- a/snippets/sumPower.md +++ b/snippets/sumPower.md @@ -15,5 +15,4 @@ const sumPower = (end,power = 2,start = 1) => sumPower(10); // 385 sumPower(10,3); //3025 sumPower(10,3,5); //2925 -sumPower(10,undefined,5); //355 ```