Tell us what’s happening:
Not working for the last two test cases.
What I am doing wrong?
**Your code so far**
// greatest common divisor
function gcd(a, b){
if(a < b){
[a, b] = [b, a]
}
if(a % b === 0){
return b;
}
else{
return gcd(a, a%b);
}
}
// find lcm of two numbers
function lcm(a , b){
return (a * b) / gcd(a, b);
}
// main function
function smallestCommons(arr) {
// get starting number and ending number
let min = Math.min(arr[0], arr[1]);
let max = Math.max(arr[0], arr[1]);
let multiple = max;
for(let i = min; i < max; i++){
multiple = lcm(multiple, i);
}
console.log(multiple);
return multiple;
}
smallestCommons([1,5]);
smallestCommons([1, 13]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
.
Challenge: Smallest Common Multiple
Link to the challenge: