#1

#1

[Week 3 - Mock Test] Between Two Sets

Q. There will be two arrays of integers. Determine all integers that satisfy the following two conditions:

1. The elements of the first array are all factors of the integer being considered. 2. 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 a = [2, 6] b = [24, 36] There are two numbers between the arrays: 6 and 12 6 % 2 = 0 , 6 % 6 = 0 and 24 % 6 = 0 , 36 % 6 = 0 for the first value. 12 % 2 = 0 , 12 % 6 = 0 and 24 % 12 = 0 , 36 % 12 = 0 for the second value. Return 2.

function getTotalX(a, b) { // Write your code here var low = a[a.length -1] var high = b[0] let num_count = 0; for (let i = low; i <= high; i++) { if (a.every(val => (i % val == 0))) { if (b.every(val => (val % i == 0))) { num_count++; } } } return num_count; }

Related Post.

https://bomiismybestie.tistory.com/44

from http://bomiismybestie.tistory.com/54 by ccl(A) rewrite - 2021-12-11 07:02:16