-
Notifications
You must be signed in to change notification settings - Fork 0
/
BetweenTwoSets.js
68 lines (68 loc) · 1.48 KB
/
BetweenTwoSets.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
function getMax(array) {
let max = array[0];
for (let i = 0; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
function getMin(array) {
let min = array[0];
for (let i = 0; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
}
function ifExist(array, item) {
if (array.includes(item)) {
return true;
}
return false;
}
function getCommonElementCount(array1, array2) {
let count = 0;
let common = [];
for (let i = 0; i < array1.length; i++) {
if (array2.includes(array1[i])) {
count++;
common.push(array1[i]);
}
}
return count;
}
function getTotalX(a, b) {
let range = [getMax(a), parseInt(getMin(b))];
let divisibleByA = [];
let BisDivisible = [];
for (let i = range[0]; i <= range[1]; i++) {
let status = true;
for (let j = 0; j < a.length; j++) {
if (i % a[j] !== 0) {
status = false;
}
}
if (status) {
if (!ifExist(divisibleByA, i)) {
divisibleByA.push(i);
}
}
}
console.log(divisibleByA);
for (let i = range[0]; i <= range[1]; i++) {
let status = true;
for (let j = 0; j < b.length; j++) {
if (b[j] % i !== 0) {
status = false;
}
}
if (status) {
if (!ifExist(BisDivisible, i)) {
BisDivisible.push(i);
}
}
}
return getCommonElementCount(divisibleByA, BisDivisible);
}