Basic recursion
IntuitionI see that this is going to be a recursive function since I would have to flatten the nested arrays too.ApproachFirst I have to iterate the given array
# Intuition\nI see that this is going to be a recursive function since I would have to flatten the nested arrays too.\n\n\n# Approach\nFirst I have to iterate the given array and check if the depth is grater than 0, if not, return the array since the job is done. If n>0, iterate the array and check every position: if the position is a number, add it to the result array, else, apply the same function recursively to the array and n-1 depth.\n\n\n# Code\n```javascript []\n/**\n * @param {Array} arr\n * @param {number} depth\n * @return {Array}\n */\nvar flat = function (arr, n) {\n  if (n === 0) {\n    return arr;\n  }\n\n  const result = [];\n\n  arr.forEach((position) => {\n    if (typeof position === "number") {\n      result.push(position);\n    } else {\n      result.push(...flat(position, n - 1));\n    }\n  });\n\n  return result;\n};\n\n```
['JavaScript']