FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Interview-Question/StorePrimeNumbers.js at master · namitmalasi/JavaScript-Interview-Question · GitHub
namitmalasi
/
JavaScript-Interview-Question
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
4
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Interview-Question
/
StorePrimeNumbers.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (21 loc) · 442 Bytes
Breadcrumbs
JavaScript-Interview-Question
/
StorePrimeNumbers.js
Copy path
File metadata and controls
27 lines (21 loc) · 442 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
function
StorePrimeNumbers
(
n
)
{
/* Function to store first n prime_numbers in an array
Return the array containing the prime numbers */
let
array
=
[
]
;
let
x
=
2
;
while
(
array
.
length
<
n
)
{
let
flag
=
true
;
for
(
let
i
=
2
;
i
<
x
;
i
++
)
{
if
(
x
%
i
===
0
)
{
flag
=
false
;
break
;
}
}
if
(
flag
)
{
array
.
push
(
x
)
;
}
x
++
;
}
return
array
;
}
console
.
log
(
StorePrimeNumbers
(
8
)
)
Back
|
FazBrowse Home
|
New Git URL