✔️ JavaScript solution using Recursion || Easiest Solution !!!
 # Intuition  \n\n\n# Approach\n\n1. Write a recursive function that keeps track of the current depth.\n2. If the current depth >= the maximum depth, always jus
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Write a recursive function that keeps track of the current depth.\n2. If the current depth >= the maximum depth, always just push the value to the returned array.\n3. Otherwise, recursively call flat on the array.\n\n<!-- # Complexity -->\n\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    const res = [];\n\n    function helper(arr,depth) {\n        for(const val of arr) {\n            if(typeof(val) === \'object\' && depth < n) {\n                helper(val,depth + 1);\n            } else {\n                res.push(val);\n            }\n        }\n        return res;\n    }\n    return helper(arr,0);\n};\n```\n\n# Code Efficiency\n![Screenshot 2023-08-31 125758.png](https://assets.leetcode.com/users/images/2057208b-67d1-49f0-a3cb-1375472804a6_1693467241.863696.png)\n\n> Do UPVOTE if you liked the solution \uD83D\uDC4D\uD83D\uDC4D
['Recursion', 'JavaScript']