-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathprimeupto100.js
More file actions
36 lines (28 loc) · 815 Bytes
/
primeupto100.js
File metadata and controls
36 lines (28 loc) · 815 Bytes
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
/*
Write a function `getPrimesUpTo100` which returns an array of all prime numbers up to 100.
What is a prime number?
- A prime number is a number greater than 1 that has no divisors other than 1 and itself.
Example:
- Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
- Input: There is no input, the function returns an array of primes.
- Input: N/A
Once you've implemented the logic, test your code by running
- `npm run test-prime`
*/
function getPrimesUpTo100() {
let arr=[];
for(let i=2; i<=100; i++){
let isPrime=true;
for(let j=2; j*j<=i; j++){
if(i%j==0){
isPrime=false;
break
}
}
if(isPrime){
arr.push(i);
}
}
return arr;
}
module.exports = { getPrimesUpTo100 };