-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
290 lines (251 loc) · 3.67 KB
/
app.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// ---- 0.2 Function
// No 1
function meterToFoot(m)
{
let oneMeterIsEqualTo = 3.28084;
let feet = m*oneMeterIsEqualTo;
console.log(feet);
return feet;
}
// No 2
function area(width, height)
{
let area = width*height;
console.log(area);
return area;
}
// No 3
function cost(h, m, s)
{
let costPerMinutes = 1.5;
if (s<60 && s>=0)
{
var totalMins = 0;
totalMins += h*60;
totalMins += m;
if(s>0)
{
totalMins += 1;
}
else
{
// do nothing
}
let totalCost = costPerMinutes*totalMins
console.log(totalCost);
return totalCost;
}
else
{
console.log(`wrong second`);
return null;
}
}
// No 4
function interest(n)
{
let interest = 1.25/100;
let total = n + n*interest;
console.log(total);
return total;
}
// No 5
function areaOfCircle(r)
{
let area = Math.PI*r*r
console.log(area);
return area;
}
// No 6
function degreeToRadian(d)
{
let radian = `${d/180} PI`;
console.log(radian);
return degreeToRadian;
}
// No 7
function distance(x1, y1, x2, y2)
{
let max_x = Math.max(x1,x2);
let min_x = Math.min(x1,x2);
let max_y = Math.max(y1,y2);
let min_y = Math.min(y1,y2);
let delta_x = max_x - min_x;
let delta_y = max_y - min_y;
let length_power_2 = (delta_x*delta_x)+(delta_y*delta_y);
let length = Math.sqrt(length_power_2);
console.log(length);
return length;
}
// No 8
function container(x, w)
{
let item_wight = x;
let support_weight = w;
var number_of_items = support_weight/item_wight;
number_of_items = Math.floor(number_of_items);
console.log(number_of_items);
return number_of_items;
}
// ---- 0.4 Condition
// No 1
function max3(a,b,c)
{
var max = 0;
if (a>=b && a>=c)
{
max = a;
}
else if (b>=a && b>=c)
{
max = b;
}
else if (c>=a && c>=b)
{
max = c;
}
else
{
//
}
console.log(max);
return max;
}
// No 2
function sumEven(n)
{
var i = 2;
var sum = 0;
while(i<=n)
{
sum+=i;
i+=2;
}
console.log(sum);
return sum;
}
// No 3
function divider(n)
{
var counter = 1;
var dividers = [];
while (counter <= n)
{
if (n % counter == 0)
{
dividers.push(counter);
}
counter+=1;
}
console.log(dividers);
return dividers;
}
// No 4
function isPrime(p)
{
var counter = 2
var isPrime = true
if(p>0)
{
while (counter < p)
{
if ( p%counter == 0)
{
isPrime = false
}
counter += 1;
}
console.log(isPrime);
return isPrime;
}
else
{
console.log(`must be greater than 0`);
}
}
// No 5
function gcd(a, b)
{
var min = Math.min(a,b);
var max = Math.max(a,b);
var counter = 1;
var gcd = 1;
while(counter<=min)
{
if(min%counter == 0 && max%counter ==0)
{
gcd = counter;
}
counter += 1;
}
console.log(gcd);
return gcd;
}
// No 6
function lcm(a, b)
{
let divide = gcd(a,b);
let lcm = (a/divide)*(b/divide)*divide;
console.log(lcm);
return lcm;
}
// No 7
function countOdd(a, b)
{
var min = Math.min(a,b);
let max = Math.max(a,b);
var odds = [];
if (min%2 == 0)
{
min += 1;
console.log(`first is even`);
}
else
{
//
}
var counter = min;
while(counter <= max)
{
odds.push(counter);
counter += 2;
}
console.log(odds.length);
return odds.length;
}
// No 8
function divide35(n)
{
var max = n;
var counter = 1;
var ableToDivide = [];
while (counter <= max)
{
if (counter%3 == 0 || counter%5 == 0)
{
ableToDivide.push(counter);
}
counter += 1;
}
console.log(ableToDivide.length);
return ableToDivide.length;
}
// No 9
function countDivider(a, b, k)
{
var min = a;
var max = b;
var counter = a;
var ableToDivide = [];
while (counter <= b)
{
if(counter%k ==0)
{
ableToDivide.push(counter);
}
counter += 1;
}
console.log(ableToDivide.length)
return ableToDivide.length
}
countDivider(10, 18, 5);