-
Notifications
You must be signed in to change notification settings - Fork 0
/
primenumber.js
44 lines (30 loc) · 933 Bytes
/
primenumber.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
// using IIFE AND ANNONYMOUS FUNCTION
var array = [11, 23, 19, 12, 25, 31, 55, 21, 13, 29, 1, 0, 37, 59, 17];
(function (array) {
console.log(array.filter((number) => {
if (number <= 1)
return false
for (var i = 2; i < number; i++) {
if (number % i == 0)
return false
}
return true
}))
})(array);
//output- [11, 23, 19, 31, 13, 29, 37, 59, 17]
//below- using arrow function
var array1 = [11, 23, 19, 12, 25, 31, 55, 21, 13, 29, 1, 0, 37, 59, 17];
var prime = (array1) => {
var store = array1.filter((number) => {
if (number <= 1)
return false
for (var i = 2; i < number; i++) {
if (number % i == 0)
return false
}
return true
})
console.log(store)
}
prime(array1);
//output- [11, 23, 19, 31, 13, 29, 37, 59, 17]