functionsumSquareDifference(min,max){letsumOfSquares=0;letsquareOfSums=0;for(i=min;i<max+1;i++){sumOfSquares+=i**2;squareOfSums+=i;}return(squareOfSums**2)-sumOfSquares;}conststartTime=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
Here is my nodejs solution
output
Yours performs faster than the one I submitted, and still looks nice, well done !
EDIT: some of the
let
s could be replaced withconst
though 🙈true