re: Project Euler #6 - Sum Square Difference VIEW POST

FULL DISCUSSION
 

Here is my nodejs solution

function sumSquareDifference(min, max) {
    let sumOfSquares = 0;
    let squareOfSums = 0;
    for (i = min; i < max + 1; i++) {
        sumOfSquares += i ** 2;
        squareOfSums += i;
    }

    return (squareOfSums ** 2) - sumOfSquares;
}
const startTime = Date.now();
console.log(`The difference between the sum of the squares of the first one
 hundred natural numbers and the square of the sum,
is ${sumSquareDifference(1, 100)}`);
console.log(`Time Taken: ${Math.round(Date.now() - startTime)}ms`);

output

The difference between the sum of the squares of the first one hundred natural numbers and the square of the sum,is 25164150
Time Taken: 2ms
 

Yours performs faster than the one I submitted, and still looks nice, well done !

EDIT: some of the lets could be replaced with const though 🙈

 
code of conduct - report abuse