简单的递归
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\n/**\n * @param {Array} arr\n * @param {number} depth\n * @return {Array}\n */\nvar flat = function (arr, n) {\n    let ret = []\n    let curDep = -1\n    function helper(subArr) {\n        curDep++\n        if (curDep < n) {\n            subArr.forEach(item => {\n                if(Array.isArray(item)) {\n                    helper(item)\n                } else {\n                    ret.push(item)\n                }\n            })\n        } else {\n            ret.push(subArr)\n        }\n        curDep--\n    }\n    arr.forEach(item => {\n        if(Array.isArray(item)) {\n            helper(item)\n        } else {\n            ret.push(item)\n        }\n    })\n    return ret\n};\n```
['JavaScript']