Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created April 29, 2020 21:26
Show Gist options
  • Save gavinsykes/25986b9e3de3040b4227386614fad0da to your computer and use it in GitHub Desktop.
Save gavinsykes/25986b9e3de3040b4227386614fad0da to your computer and use it in GitHub Desktop.
const euler6 = num => {
let n = +num;
let result = 0,
sumsquares = 0,
sum = 0,
squaresum = 0;
if (n < 1 || !Number.isInteger(n)) {
return undefined;
}
for(let i = 1; i <= n; i++) {
sumsquares += Math.pow(i,2);
}
for(let i = 1; i <= n; i++) {
sum += i;
}
squaresum = Math.pow(sum,2);
result = Math.abs(squaresum - sumsquares);
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment