Files
30-seconds-of-code/test/flatten/flatten.js
Angelos Chalaris 81712c6a60 Resolve #624
Also the testing for isSorted is a lot more robust now.
2018-03-09 20:23:10 +02:00

3 lines
156 B
JavaScript

const flatten = (arr, depth = 1) =>
arr.reduce((a, v) => a.concat(depth > 1 && Array.isArray(v) ? flatten(v, depth - 1) : v), []);
module.exports = flatten;