GOOD ONE | RECURSION | EASY MEDIUM
Code
# Code
```javascript []
function flatten(array, currentDepth, maxDepth, result) {
    if (currentDepth > maxDepth) {
        result.push(array);
        return;
    }

    for (let el of array) {
        if (Array.isArray(el)) {
            flatten(el, currentDepth + 1, maxDepth, result);
        } else {
            result.push(el);
        }
    }
    return;
}

var flat = function (arr, n) {
    const result = [];
    flatten(arr, 0, n, result);
    return result;
};
```
['JavaScript']