100% recursive memoization
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nRecursion \n\n# Complex
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nRecursion \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```\n/**\n * @param {any[]} arr\n * @param {number} depth\n * @return {any[]}\n */\nvar flat = function (arr, n) {\n    if(n==0) return arr;\n    let result = [];\n    const traverse = (a, n) => {\n        for(let i in a) {\n            if(n>0 && Array.isArray(a[i]))\n                traverse(a[i], n-1)\n            else\n                result.push(a[i])\n        }\n    }\n    traverse(arr, n);\n    return result;\n};\n```
['JavaScript']