• + 1 comment

    Javascript Code:

    function getTotalX(a, b) {
        // Write your code here
        let maxValue = Math.max(...a);
        let minValue = Math.min(...b);
    
        let i = 2;
        let elements = [];
        let element = maxValue;
        while(element<=minValue){ 
            let factors = a.filter(num=>element%num == 0); 
            if(factors.length == a.length){ 
                let isFactor = b.filter(num1=>num1%element == 0);
                if(isFactor.length == b.length){
                    elements.push(element);
                }
            }
            element=maxValue*i; 
            i++; 
            
        }
        return elements.length;
    }