Problem, as an interviewer would state it:
"Implement Array.prototype.myFlat(depth) from scratch — recursively flattening nested arrays up to the given depth, matching real native flat's own documented contract, including its default depth of 1."
Examples:
[1, [2, 3], [4, [5, 6]]].myFlat(); // [1, 2, 3, 4, [5, 6]] -- default depth 1
[1, [2, 3], [4, [5, 6]]].myFlat(2); // [1, 2, 3, 4, 5, 6]
Clarifying questions expected:
- What is the real, correct default depth when no argument is passed?
- Should Infinity be a genuinely valid depth argument, flattening completely regardless of nesting?
- Does flat() also remove real holes in a sparse array, at every flattened level?
Code / implementation expected: Yes — real, direct proof against the ACTUAL native flat, at the default depth, an explicit depth of 2, and Infinity, confirming identical output in every case.