Find the Least Common Multiple

Tell us what’s happening:
So I have tried to create this ‘multiple’ function which calls itself using the every() method to check until the number is a multiple of all given numbers. I have kinda confused myself in the process, I feel very close yet also feel so far. I don’t know if my train of thought is correct. Any pointers will be of great help. thank you.

  **Your code so far**

function smallestCommons(arr) {
  const arr1 = arr.sort((a,b)=>a-b)
//console.log(arr)
const [a,b] = arr1;
//console.log(a,b)
let lcm = 0;

const multiple = (a,b,lcm)=>{    
  //console.log(lcm)
  let i=a;    
  while(i<=b){
    if(i==1){lcm += b; i++;};
    //console.log(i,lcm)
    if(i > 1 && lcm%i != 0){                
      lcm += b;     
      i++;
      //console.log(i,lcm)
    }else{        
      break        
    }      
  }
  //console.log(lcm)
  let arr2 = []
  for(let j=a; j<b+1; j++){
    arr2.push(j)      
  }
  //console.log(arr2)
  const isMultiple = (i) => lcm % i == 0;
  //console.log(lcm)    
  if((arr2.every(isMultiple)) == false){
    multiple(a,b,lcm)      
  }else{
    console.log(lcm)
    return lcm
  }   
  
} 

//multiple(a,b,lcm)
console.log(multiple(a,b,lcm))
//return arr;
}

smallestCommons([1,5]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Smallest Common Multiple

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.