So easy 92%-85%✅🤛🍻
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n\n# Code\n\n/**\n * @
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Code\n```\n/**\n * @param {Array} arr - The input array to be flattened.\n * @param {number} depth - The depth to which the array should be flattened.\n * @return {Array} - The flattened array.\n */\nvar flat = function (arr, depth, result = [], currentCycle = 0) {\n    // Iterate through each element in the array\n    for (let index = 0; index < arr.length; index++) {\n        // If the current element is an array and the depth hasn\'t been reached\n        if (Array.isArray(arr[index]) && currentCycle < depth) {\n            // Recursively call flat function with the nested array\n            flat(arr[index], depth, result, currentCycle + 1);\n        } else {\n            // If the element is not an array or the depth limit is reached, push it to tempArray\n            result.push(arr[index]);\n        }\n    }\n    // Return the flattened array\n    return result;\n};\n\n\n```\n# UPVOTE _ PLEASE\n![4a40bdf4-b9f2-4528-a075-6ef5d4648ece_1709874956.7472744.png](https://assets.leetcode.com/users/images/2bf5a833-6143-4bef-b500-263cb352a8c1_1709905102.1172223.png)\n\n\n
['JavaScript']