Recursive check
Intuition\nIt\'s basically just recursive iteration through current array.\n\n# Approach\nCreate a function which will be iterating through current array and if
# Intuition\nIt\'s basically just recursive iteration through current array.\n\n# Approach\nCreate a function which will be iterating through current array and if current item is an array, recursively iterate through it as well if we still not exceeded allowed depth.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```typescript []\ntype MultiDimensionalArray = (number | MultiDimensionalArray)[];\n\nvar flat = function (arr:  MultiDimensionalArray, n: number):  MultiDimensionalArray {\n    const ans = [];\n    let remainingDepth = n;\n\n    function recursiveCheck(array: MultiDimensionalArray, currentDepth: number) {\n\n        for (let i = 0; i < array.length; i++) {\n            const item = array[i];\n\n            if (typeof item === \'number\' || currentDepth === 0) {\n                ans.push(item);\n            } else {\n                recursiveCheck(item, currentDepth - 1);\n            }\n        }\n\n    }\n\n    recursiveCheck(arr, remainingDepth)\n\n    return ans;\n};\n```
['TypeScript']