Also the testing for isSorted is a lot more robust now.
This commit is contained in:
Angelos Chalaris
2018-03-09 20:23:10 +02:00
parent 02a3064840
commit 81712c6a60
6 changed files with 1076 additions and 1085 deletions

View File

@ -1,5 +1,3 @@
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), []);
module.exports = flatten;