The current solution right now as of May 20, 2021, is that it uses function customReduce(arr, reducer, initialValue = 0) { which is to assume initialValue is 0, but it can't always be the case.
function customReduce(arr, reducer, initialValue = 0) {
[1,3,5].reduce((a,b) => a * b) // => 15 customReduce([1,3,5], (a,b) => a * b) // => 0
so essentially, one way is that when there is no initial value, we'd use the first value as the initial value instead.
Thank you for pointing out Kenneth. Will edit that part definitely.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The current solution right now as of May 20, 2021, is that it uses
function customReduce(arr, reducer, initialValue = 0) {which is to assume initialValue is 0, but it can't always be the case.so essentially, one way is that when there is no initial value, we'd use the first value as the initial value instead.
Thank you for pointing out Kenneth. Will edit that part definitely.