We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent be95cc4 commit b3159b9Copy full SHA for b3159b9
Project-Euler/Problem6.js
@@ -0,0 +1,15 @@
1
+// https://projecteuler.net/problem=6
2
+
3
+const num = 100 // number we are checking; change to 10 to check 10 from example
4
5
+const squareDifference = (num) => {
6
+ let sumOfSquares = 0
7
+ let sums = 0
8
+ for (let i = 1; i <= num; i++) {
9
+ sumOfSquares += i ** 2 // add squares to the sum of squares
10
+ sums += i // add number to sum to square later
11
+ }
12
+ return (sums ** 2) - sumOfSquares // difference of square of the total sum and sum of squares
13
+}
14
15
+console.log(squareDifference(num))
0 commit comments