Files
30-seconds-of-code/test/flattenDepth/flattenDepth.js
2018-01-11 05:27:49 -05:00

4 lines
191 B
JavaScript

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