-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavascript Basic.js
More file actions
145 lines (116 loc) · 2.17 KB
/
Copy pathJavascript Basic.js
File metadata and controls
145 lines (116 loc) · 2.17 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// 1.
function myFunction(a, b) {
return a+b;
}
// 2.
function myFunction(a, b){
return a === b;
}
// 3.
function myFunction(a){
return typeof a;
}
// 4.
function myFunction(a,n) {
return a[n-1];
}
// 5.
function myFunction(a) {
return a.slice(3);
}
// 6.
function myFunction(str) {
return str.substr(-3, 3);
}
// 7
function myFunction(a) {
return a.substr(0,3);
}
// 8
function myFunction(a) {
return a.slice(0, a.length/2);
}
// 9
function myFunction(a) {
return a.slice(0,-3);
}
// 10
function myFunction(a, b) {
return (a*(b/100));
}
// 11
function myFunction(a, b, c, d, e, f) {
return Math.pow((a+b-c)*d/e,f)
}
// 12
function myFunction(a) {
if (a%2 == 0)
return true;
else
return false;
}
// 13.
function myFunction(a,b) {
return b.split('').reduce((prev, current) => current === a ? prev+1 : prev,0);
}
// 14
function myFunction(a) {
if (a%1 == 0 )
return true;
else return false;
}
// 15
function myFunction(a, b) {
if (a<b) return a/b;
else return a*b;
}
// 16
function myFunction(a, b) {
if (a.includes(b)) {
result = b.concat(a);
} else {
result = a.concat(b);
} return result;
}
// 17
function myFunction(a) {
return Math.round(a * 100) / 100;
}
// 18
function myFunction(a) {
return Array.from(a.toString()).map(Number);
}
// 19
function myFunction(a, b) {
return (a.charAt(0).toUpperCase() + a.slice(1)+b.split("").reverse().join("")).replace('%','');
}
// 20
function myFunction(a) {
function isPrime(a) {
if (a <= 1) return false;
if (a <= 3) return true;
if (a%2 == 0 || a%3 == 0) return false;
for (let i=5; i*i<=a; i=i+6)
if (a%i == 0 || a%(i+2) == 0)
return false;
return true;
}
function nextPrime(N) {
if (N <= 1)
return 2;
let prime = N;
let found = false;
while (!found) {
prime++;
if (isPrime(prime))
found = true;
}
return prime;
}
if (isPrime(a) == true) {
return a;
} else {
return nextPrime(a);
}
}
// 21