Created
April 29, 2020 21:26
-
-
Save gavinsykes/25986b9e3de3040b4227386614fad0da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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