Truly a JavaScript miracle!
IntuitionAt first, I considered the array as one-dimensional and thought I could loop through each element to dive into the 2nd, 3rd, and 4th dimensions. Howeve
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
At first, I considered the array as one-dimensional and thought I could loop through each element to dive into the 2nd, 3rd, and 4th dimensions. However, it became clear that this approach would be quite challenging.
# Approach
<!-- Describe your approach to solving the problem. -->
Later, I researched the flat function and realized it takes a depth parameter, allowing me to solve the problem with a single line of code.
# 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}
 */
var flat = function (arr, n) {
  if (n === 0) {
    return arr;
  }
  return arr.flat(n);
};
```
['JavaScript']