Resolve #622
This commit is contained in:
@ -9,9 +9,11 @@ Omit the second argument, `depth` to flatten only to a depth of `1` (single flat
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const flatten = (arr, depth = 1) =>
|
const flatten = (arr, depth = 1) =>
|
||||||
depth !== 1
|
arr.reduce(
|
||||||
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
|
(a, v) =>
|
||||||
: arr.reduce((a, v) => a.concat(v), []);
|
a.concat(depth > 1 && Array.isArray(v) ? flatten(v, depth - 1) : v),
|
||||||
|
[],
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user