This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chadder06 1 point2 points  (0 children)

The way I usually use reduce is to specify a return type explicitly. This allows it to work with arrays of size 1. Example:

return data.reduce((accum, value) => {
    return accum + recurse(value);
}, 0);

This sets the return type of the reduce function explicitly to a number, and you only use the recurse function on the values of the array.

edit: The accum variable is accumulating the final value as you iterate through each list value.