Difficulty: 3/10recursion, array handling, performancejavascriptCopyScenario Questions0-2 years experience1How would you write a function that takes an array which may contain nested arrays and returns a new flat array with all values on a single level?2If you call your flatten function on [1, [2, [3, 4]], 5], what should the result be and why?3What would happen if the input contains non‑array values like null or objects, and how would you handle that?Follow-up QuestionsHow would you modify the function to skip non‑array values like objects or null?What trade‑offs exist between a recursive and an iterative implementation in terms of memory usage?If the input could contain circular references, how would you protect against infinite loops?Suggest Improvement