Merge pull request #329 from skatcat31/update/flatten

[UPDATE] Flatten updated to use ES6 spread
This commit is contained in:
Angelos Chalaris
2017-12-23 12:02:38 +02:00
committed by GitHub

View File

@ -2,9 +2,9 @@
Flattens an array.
Use `Array.reduce()` to get all elements inside the array and `concat()` to flatten them.
Use a new array and concatenate it with the spread input array causing a shallow denesting of any contained arrays.
```js
const flatten = arr => arr.reduce((a, v) => a.concat(v), []);
const flatten = arr => [ ].concat( ...arr );
// flatten([1,[2],3,4]) -> [1,2,3,4]
```