hardJS ES5#61

Array.reduce manually

Prompt

Implement your own version of Array.prototype.reduce as myReduce(arr, callback, initialValue). Handle both arities correctly:

  1. With an initial value — even an explicit undefined counts as provided (detect via arguments.length, not === undefined)
  2. Without one — the first element seeds the accumulator and iteration starts at index 1
  3. Empty array with no initial value must throw a TypeError (per spec)

Hints

Solution

Your Code

15 min

Tests

Click Run to test your code