1. const flatten = (arr, depth) => {
    2. if (!Array.isArray(arr) || depth <= 0) return arr
    3. return arr.reduce((acc, cur) =>{
    4. if (Array.isArray(cur)) {
    5. return acc.concat(flatten(cur, depth -1))
    6. } else {
    7. return acc.concat(cur)
    8. }
    9. }, [])
    10. }