|| Beginner approach || 
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```javascript []
/**
 * @param {Array} arr
 * @param {number} depth
 * @return {Array}
 */
// Recursive Approach
function flat(arr, depth) {
  if (depth === 0) {
    return arr.slice(); // Base case: return a shallow copy of the array
  }

  let flattened = [];

  for (let i = 0; i < arr.length; i++) {
    if (Array.isArray(arr[i])) {
      const nested = flat(arr[i], depth - 1); // Recursively flatten nested arrays
      flattened.push(...nested); // Concatenate flattened nested arrays to the result
    } else {
      flattened.push(arr[i]); // Push individual elements to the result
    }
  }

  return flattened; // Return the flattened array
}
```
['JavaScript']