Problem, as an interviewer would state it:
"Implement Array.prototype.myMap from scratch, matching the real, native Array.prototype.map — including its thisArg support and its real behavior on a sparse array."
Examples:
[1,2,3].myMap(n => n * 2); // [2, 4, 6]
Clarifying questions expected:
- Does the callback need to receive the current index and the whole original array, matching the real native signature?
- Should a real, optional
thisArgsecond parameter be supported, matchingArray.prototype.map's own real contract? - What is real, native map's own documented behavior for a "hole" in a sparse array — does the callback even run for it?
Code / implementation expected: Yes — real, direct proof against the ACTUAL native Array.prototype.map, across 4 real cases including the subtle sparse-array hole-skipping behavior.