Performance measuring, scroll to top, array flattening
This commit is contained in:
9
snippets/flatten-array.md
Normal file
9
snippets/flatten-array.md
Normal file
@ -0,0 +1,9 @@
|
||||
### Flatten array
|
||||
|
||||
Use recursion.
|
||||
Use `reduce()` to get all elements that are not arrays, flatten each element that is an array.
|
||||
|
||||
```js
|
||||
var flatten = arr =>
|
||||
arr.reduce( (a, v) => a.concat( Array.isArray(v) ? flatten(v) : v ), []);
|
||||
```
|
||||
Reference in New Issue
Block a user