SIMPLE JS CODING - rs-hash/Senior GitHub Wiki

Sum of integers n

function sumOfNumbersMath(n) {
    return Math.floor((n * (n + 1)) / 2);
}

function sumOfNumbersSpreadReduce(n) {
    return [...Array(n).keys()].reduce((acc, val) => acc + val + 1, 0);
}