🗓️ Daily LeetCoding Challenge Day 26|| 🔥 JS SOL
\n# Code\n\nvar flat = function(arr, depth) {\n  const stack = [...arr.map(item => [item, depth])];\n  const result = [];\n\n  while (stack.length > 0) {\n    c
\n# Code\n```\nvar flat = function(arr, depth) {\n  const stack = [...arr.map(item => [item, depth])];\n  const result = [];\n\n  while (stack.length > 0) {\n    const [item, depth] = stack.pop();\n\n    if (Array.isArray(item) && depth > 0) {\n      stack.push(...item.map(subItem => [subItem, depth - 1]));\n    } else {\n      result.push(item);\n    }\n  }\n\n  return result.reverse();\n};\n\n```
['JavaScript']