JavaScript | Typescript Solution with recursion
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) \nO(n)\n\n- Space comp
# 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$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$ (If we consider the resulting array)\n\n\n# Code\n```typescript []\ntype MultiDimensionalArray = (number | MultiDimensionalArray)[];\n\nvar flat = function (arr:  MultiDimensionalArray, n: number):  MultiDimensionalArray {\n    if(n === 0) return arr\n\n    let resArr: MultiDimensionalArray = []\n\n    for (let i = 0; i < arr.length; i++) {\n        if(Array.isArray(arr[i])) {\n            resArr.push(...flat(arr[i] as MultiDimensionalArray, n-1))\n        } else {\n            resArr.push(arr[i])\n        }\n    }\n    return resArr\n};\n```
['Recursion', 'TypeScript']