JavaScript | Recursive Solution
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:\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) {\n    return arr;\n  }\n\n  let ans = [];\n\n  for (let i = 0; i < arr.length; i++) {\n    if (Array.isArray(arr[i])) {\n      const subArray = flat(arr[i], n - 1);\n      ans.push(...subArray);\n    } else {\n      ans.push(arr[i]);\n    }\n  }\n  return ans; \n};\n```
['JavaScript']