Title description
Problem-solving ideas
- Use recursion
- Using the reduce method of the array, the initial accumulator value is set to 1, and then the index subscript +1 is accumulated.
Problem-solving code
var sumNums = function (n) {
return Array(n).fill(null).reduce((pre, item, idx) => pre + idx + 1, 0)
};