Travis build: 784 [ci skip]
This commit is contained in:
36
README.md
36
README.md
@ -177,6 +177,7 @@
|
|||||||
* [`round`](#round)
|
* [`round`](#round)
|
||||||
* [`standardDeviation`](#standarddeviation)
|
* [`standardDeviation`](#standarddeviation)
|
||||||
* [`sum`](#sum)
|
* [`sum`](#sum)
|
||||||
|
* [`sumPower`](#sumpower)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@ -237,7 +238,7 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### 💎 Utility
|
### 🔧 Utility
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -3094,6 +3095,36 @@ sum([1, 2, 3, 4]); // 10
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### sumPower
|
||||||
|
|
||||||
|
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`.
|
||||||
|
Omit the third argument, `start`, to use a default starting value of `1`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const sumPower = (end, power = 2, start = 1) =>
|
||||||
|
Array(end + 1 - start)
|
||||||
|
.fill(0)
|
||||||
|
.map((x, i) => (i + start) ** power)
|
||||||
|
.reduce((a, b) => a + b, 0);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
sumPower(10); // 385
|
||||||
|
sumPower(10, 3); //3025
|
||||||
|
sumPower(10, 3, 5); //2925
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
---
|
---
|
||||||
## 📦 Node
|
## 📦 Node
|
||||||
|
|
||||||
@ -4012,7 +4043,7 @@ words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"]
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
---
|
---
|
||||||
## 💎 Utility
|
## 🔧 Utility
|
||||||
|
|
||||||
### coalesce
|
### coalesce
|
||||||
|
|
||||||
@ -4211,6 +4242,7 @@ Use the spread operator (`...`) to check if the provided argument is iterable in
|
|||||||
```js
|
```js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const isArrayLike = val =>
|
const isArrayLike = val =>
|
||||||
try {return [...val], true; }
|
try {return [...val], true; }
|
||||||
catch (e) { return false; }
|
catch (e) { return false; }
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -7,6 +7,7 @@ Use the spread operator (`...`) to check if the provided argument is iterable in
|
|||||||
```js
|
```js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const isArrayLike = val =>
|
const isArrayLike = val =>
|
||||||
try {return [...val], true; }
|
try {return [...val], true; }
|
||||||
catch (e) { return false; }
|
catch (e) { return false; }
|
||||||
|
|||||||
@ -8,7 +8,10 @@ Omit the third argument, `start`, to use a default starting value of `1`.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const sumPower = (end, power = 2, start = 1) =>
|
const sumPower = (end, power = 2, start = 1) =>
|
||||||
Array(end + 1 - 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
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user