getTotalX.js

    0

    0

    The code splits the input arrays (a and b) into two new arrays called cloneA and cloneB. It then compares each element in cloneA and cloneB. If the elements are equal, the code increments the result variable by 1. Otherwise, it increments the index variable by 1 and sets the result variable to the index of the first element in cloneA that equals the element in cloneB.

    function getTotalX(a, b) {
      // Write your code here
        let result = 0;
        let index = 1;
        let cloneA = a.splice(1, a.length); // clone new array of a but not a[0]
        while(a[0] * index <= b[0]) {
            if(
              cloneA.every(item => (a[0] * index) % item === 0)
              &&
              b.every(item => item % (a[0] * index) === 0)
              ) {
                result++;
            }
            index++;
        }
        return result;
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.