Skip to content

Commit 11dcd8d

Browse files
committed
minor refactor and comments
1 parent d90e6d2 commit 11dcd8d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Project-Euler/Problem7.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
const num = 10001;
44

5-
let primes = [2,3,5,7,11,13];
5+
let primes = [2,3,5,7,11,13]; // given list of primes you start with
66

77
const calculatePrime = (num) => {
8-
let count = primes.length;
9-
let current = primes[count-1] + 1;
10-
while (count < num) {
8+
let count = primes.length; // count number of primes calculated
9+
let current = primes[count-1] + 1; // current number being assessed if prime
10+
while (count < num) { // repeat while we haven't reached goal number of primes
1111
// go through each prime and see if divisible by the previous primes
1212
let prime = false;
1313
primes.some((n, i) => {
14-
if (current % n !== 0) {
15-
if (i === count-1) {
16-
prime = true;
17-
}
18-
} else {
14+
if (current % n === 0) {
1915
return true;
2016
}
17+
if (i === count-1) {
18+
prime = true;
19+
}
2120
})
2221
if (prime) {
2322
primes.push(current);

0 commit comments

Comments
 (0)