Recursively Flatten a Deeply Nested Array Structure
Write a function that takes an arbitrarily nested array (e.g., [1, [2, [3, [4]]]]) and returns a single flat array containing all the values. Implement it using recursion, iteration (stack-based), and also as a polyfill for Array.prototype.flat(). Optionally support a depth parameter to partially flatten. This is one of the most frequently asked JavaScript questions across all experience levels.