Files
30-seconds-of-code/snippets/flatten-array.md
2017-12-12 07:11:37 -05:00

10 lines
239 B
Markdown

### Flatten array
Use recursion.
Use `reduce()` to get all elements that are not arrays, flatten each element that is an array.
```js
const flatten = arr =>
arr.reduce( (a, v) => a.concat( Array.isArray(v) ? flatten(v) : v ), []);
```