Problem, as an interviewer would state it:
"Implement Array.prototype.myReduce from scratch — matching real native reduce's own complete, documented contract, including its behavior with and without an explicit initial value."
Examples:
[1,2,3,4].reduce((acc, v) => acc + v, 0); // 10
Clarifying questions expected:
- With no initial value provided, does the FIRST present element become the implicit seed?
- What is the real, correct behavior for a genuinely empty array with no initial value — does it throw?
- Does a real hole in a sparse array need to be correctly skipped, matching real native reduce's own documented behavior?
Code / implementation expected: Yes — real, direct proof matching real native reduce, WITH an explicit initial value, WITHOUT one, and on a genuinely empty array with no seed.