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

FULL DISCUSSION
 

Javascript !

const sumSquareDifference = (n) => {
  const numbers = [...Array(n + 1).keys()];
  const sumOfSquares = numbers.reduce((accumulator, number) => accumulator + (number ** 2));
  const squareOfSum = numbers.reduce((accumulator, number) => accumulator + number) ** 2;
  return squareOfSum - sumOfSquares;
}
console.log(sumSquareDifference(10));
 

Yours is good. But I have a feeling it uses more then one for/for each loop. May explain why it is a bit slower then mine. Not sure.

 

Yeah, also the fact that I'm iterating 2 times the same array !

code of conduct - report abuse