Prompt
Implement your own version of Array.prototype.reduce as myReduce(arr, callback, initialValue).
Handle both arities correctly:
- With an initial value — even an explicit
undefinedcounts as provided (detect viaarguments.length, not=== undefined) - Without one — the first element seeds the accumulator and iteration starts at index 1
- Empty array with no initial value must throw a TypeError (per spec)
Hints
Solution
Your Code
15 min