Travis build: 391
This commit is contained in:
@ -9,10 +9,11 @@ Omit the second element, `depth` to flatten only to a depth of `1` (single flatt
|
||||
|
||||
```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), []);
|
||||
depth != 1
|
||||
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flattenDepth(v, depth - 1) : v), [])
|
||||
: arr.reduce((a, v) => a.concat(v), []);
|
||||
```
|
||||
|
||||
```js
|
||||
flattenDepth([1,[2],3,4]) // [1,2,3,4]
|
||||
flattenDepth([1, [2], 3, 4]); // [1,2,3,4]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user