Flatten Deeply Nested Array || Easy Solution
Complexity

Time complexity: O(n2)


Space complexity: O(n)

Code
# Complexity
- Time complexity: O(n2)

- Space complexity: O(n)

# Code
```javascript []
/**
 * @param {Array} arr
 * @param {number} depth
 * @return {Array}
 */
var flat = function (arr, n) {
    let ans = [];
   for(const el of arr){
        if(Array.isArray(el) && n>0){
            ans.push(...flat(el, n-1));
        }else{
            ans.push(el);
        }
   }
   return ans;
};
```
['JavaScript']