-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15-betweenTwoSets.js
More file actions
49 lines (40 loc) · 969 Bytes
/
15-betweenTwoSets.js
File metadata and controls
49 lines (40 loc) · 969 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
37
38
39
40
41
42
43
44
45
46
47
48
49
function getTotalX(a, b) {
let sonuc = 0;
let multa = [];
let tekrarEdenler = [];
let maxB = Math.min(...b);
for (let i = 0; a.length > i; i++) {
let count = 1;
while (a[i] * count <= maxB) {
multa.push(a[i] * count);
count++;
}
}
multa.sort((x, y) => x - y);
let sayac = 1;
for (let i = 1; i < multa.length; i++) {
if (multa[i] === multa[i - 1]) {
sayac++;
} else {
if (sayac >= a.length && !tekrarEdenler.includes(multa[i - 1])) {
tekrarEdenler.push(multa[i - 1]);
}
sayac = 1;
}
}
if (sayac >= a.length && !tekrarEdenler.includes(multa[multa.length - 1])) {
tekrarEdenler.push(multa[multa.length - 1]);
}
for (let i = 0; tekrarEdenler.length > i; i++) {
let sayac = 0;
for (let j = 0; b.length > j; j++) {
if (b[j] % tekrarEdenler[i] == 0) {
sayac++;
}
}
if (sayac == b.length) {
sonuc++;
}
}
return sonuc;
}