Travis build: 1181
This commit is contained in:
30
README.md
30
README.md
@ -99,7 +99,6 @@ average(1, 2, 3);
|
||||
* [`everyNth`](#everynth)
|
||||
* [`filterNonUnique`](#filternonunique)
|
||||
* [`flatten`](#flatten)
|
||||
* [`flattenDepth`](#flattendepth)
|
||||
* [`forEachRight`](#foreachright)
|
||||
* [`groupBy`](#groupby)
|
||||
* [`head`](#head)
|
||||
@ -799,34 +798,6 @@ flatten([1, [2, [3, [4, 5], 6], 7], 8], 2); // [1, 2, 3, [4, 5], 6, 7, 8]
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### flattenDepth
|
||||
|
||||
Flattens an array up to the specified depth.
|
||||
|
||||
Use recursion, decrementing `depth` by 1 for each level of depth.
|
||||
Use `Array.reduce()` and `Array.concat()` to merge elements or arrays.
|
||||
Base case, for `depth` equal to `1` stops recursion.
|
||||
Omit the second element, `depth` to flatten only to a depth of `1` (single flatten).
|
||||
|
||||
```js
|
||||
const flattenDepth = (arr, depth = 1) =>
|
||||
depth != 1
|
||||
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flattenDepth(v, depth - 1) : v), [])
|
||||
: arr.reduce((a, v) => a.concat(v), []);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
flattenDepth([1, [2], 3, 4]); // [1,2,3,4]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### forEachRight
|
||||
|
||||
Executes a provided function once for each array element, starting from the array's last element.
|
||||
@ -5300,6 +5271,7 @@ const httpPost = (url, callback, data = null, err = console.error) => {
|
||||
|
||||
|
||||
|
||||
|
||||
const newPost = {
|
||||
"userId": 1,
|
||||
"id": 1337,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -29,6 +29,7 @@ const httpPost = (url, callback, data = null, err = console.error) => {
|
||||
|
||||
|
||||
|
||||
|
||||
const newPost = {
|
||||
"userId": 1,
|
||||
"id": 1337,
|
||||
|
||||
@ -44,7 +44,6 @@ factorial:math,recursion
|
||||
fibonacci:math,array
|
||||
filterNonUnique:array
|
||||
flatten:array
|
||||
flattenDepth:array,recursion
|
||||
flip:adapter,function
|
||||
forEachRight:array,function
|
||||
formatDuration:date,math,string,utility
|
||||
|
||||
Reference in New Issue
Block a user