-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_prime.js
57 lines (50 loc) · 1.03 KB
/
1_prime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
let prime1 = [];
let l = 0;
let m = 0;
let k, i, j;
function prime(number) {
for (i = 2; i <= number; i++) {
k = 2;
for (j = k; j <= i; j++) {
if (i % j === 0) {
if (i === 2) {
prime1[m] = i;
// console.log(prime1[m]);
break;
}
l++
break;
}
if (j === i - 1) {
if (i % j != 0) {
m++;
prime1[m] = i;
// console.log(prime1[m]);
break;
}
}
}
++k;
}
}
prime(200);
console.log(prime1.toString());
// Another example to Prime Number
/*
let j = 2;
let a = 200;
let string = "";
for (let i = 2; i < a; i++) {
for (let j = 2; j < i; j++) {
let b = i % j;
if (b == 0) {
break;
}
if (j === i - 1) {
string += i + ",";
}
}
}
console.log(string);
*/