In this question, you need to implement the polyfill for
Your implementation (
customReduce method) should exist on Array's prototype chain.
The reduce() method executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
A "reducer" function is called with the following arguments:
The value resulting from the previous call to callbackFn. On first call, initialValue if specified, otherwise the value of array.
The value of the current element. On first call, the value of array if an initialValue was specified, otherwise the value of array.
The index position of currentValue in the array. On the first call, 0 if initialValue was specified, otherwise 1.
The array being traversed.
A value to which previousValue is initialized the first time the callback is called. If initialValue is specified, that also causes currentValue to be initialized to the first value in the array. If initialValue is not specified, previousValue is initialized to the first value in the array, and currentValue is initialized to the second value in the array.
The value that results from running the "reducer" callback function to completion over the entire array.