8000 Update Problem006.js · imrahulkb/JavaScript@096644a · GitHub
[go: up one dir, main page]

Skip to content

Commit 096644a

Browse files
authored
Update Problem006.js
1 parent f77a970 commit 096644a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Project-Euler/Problem006.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// https://projecteuler.net/problem=6
22

33
export const squareDifference = (num = 100) => {
4-
let sumOfSquares = 0
5-
let sums = 0
6-
for (let i = 1; i <= num; i++) {
7-
sumOfSquares += i ** 2 // add squares to the sum of squares
8-
sums += i // add number to sum to square later
9-
}
4+
let sumOfSquares = (num)*(num+1)*(2*num+1)/6
5+
let sums = (num)*(num+1)/2
6+
107
return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
118
}

0 commit comments

Comments
 (0)
0