Best Solution in JAVASCRIPT solution with O(N) complexity
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 
# 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: O(n)\n\n\n- Space complexity:  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\n    let res = []\n\n    function helperRec(arr, depth){\n\n        for(const val of arr){\n            if(Array.isArray(val) && depth < n){\n                helperRec(val, depth +1)\n            }\n            else{\n                res.push(val)\n            }\n        }\n      return res\n    }\n    return helperRec(arr, 0)\n    \n};\n```
['JavaScript']