-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTotalX.js
More file actions
106 lines (71 loc) · 2.43 KB
/
Copy pathgetTotalX.js
File metadata and controls
106 lines (71 loc) · 2.43 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
/*
There will be two arrays of integers. Determine all integers that satisfy the following two conditions:
The elements of the first array are all factors of the integer being considered
The integer being considered is a factor of all elements of the second array
These numbers are referred to as being between the two arrays. Determine how many such numbers exist.
Example
There are two numbers between the arrays: and .
, , and for the first value.
, and , for the second value. Return .
Function Description
Complete the getTotalX function in the editor below. It should return the number of integers that are betwen the sets.
getTotalX has the following parameter(s):
int a[n]: an array of integers
int b[m]: an array of integers
Returns
int: the number of integers that are between the sets
Input Format
The first line contains two space-separated integers, and , the number of elements in arrays and .
The second line contains distinct space-separated integers where .
The third line contains distinct space-separated integers where .
Constraints
Sample Input
2 3
2 4
16 32 96
Sample Output
3
Explanation
2 and 4 divide evenly into 4, 8, 12 and 16.
4, 8 and 16 divide evenly into 16, 32, 96.
4, 8 and 16 are the only three numbers for which each element of a is a factor and each is a factor of all elements of b.
* Complete the 'getTotalX' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER_ARRAY a
* 2. INTEGER_ARRAY b
*
*/
function getTotalX(a, b) {
// Write your code here
let multiplierArr = [];
let arrMultiplesCounter = 0;
let multiplier = 1;
while(multiplier <= Math.min(...b)){
let arrAIndex = 0;
let validationValA = true;
while (arrAIndex < a.length){
let currVal = a[arrAIndex];
if (multipler % currVal !== 0){
validationValA = false;
}
arrAIndex++;
}
let arrBIndex = 0;
let validationValB = true;
while (iarrBIndex < b.length){
let currVal = b[arrBIndex];
if (multipler % currVal !== 0){
validationValB = false;
}
arrBIndex++;
}
if (validationValA && validationValB){
multiplierArr.push(multipler)
arrMultiplesCounter++
}
}
console.log(arrMultiplesCounter)
return arrMultiplesCounter;
}