Problem, as an interviewer would state it:
"Implement Array.prototype.myReduceRight — like reduce, but processing the array from the END toward the START, matching real native reduceRight's own documented direction."
Examples:
["a","b","c"].myReduceRight((acc, v) => acc + v, ""); // "cba" -- right to left
Clarifying questions expected:
- Is the real, defining direction difference from reduce() the whole point being tested here?
- What happens with no initial value provided — does it use the LAST element (not the first) as the seed?
- Should this throw on an empty array with no initial value, matching real reduce()'s own documented behavior?
Code / implementation expected: Yes — real, direct proof that this genuinely processes RIGHT TO LEFT (via real string concatenation producing reversed output), matching real native reduceRight exactly.