This commit is contained in:
Angelos Chalaris
2018-03-09 19:38:38 +02:00
committed by GitHub
parent 462a0a74c2
commit 1b516a8e74

View File

@ -9,9 +9,11 @@ Omit the second argument, `depth` to flatten only to a depth of `1` (single flat
```js
const flatten = (arr, depth = 1) =>
depth !== 1
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
: arr.reduce((a, v) => a.concat(v), []);
arr.reduce(
(a, v) =>
a.concat(depth > 1 && Array.isArray(v) ? flatten(v, depth - 1) : v),
[],
);
```
```js