function smallestCommons(arr){
arr.sort((a,b)=>a-b);
let x =Math.abs(arr[0]);
let y=Math.abs(arr[1]);
let mainArr = [];
for(let i = x;i<=y;i++){
mainArr.push(i);
};
function gcd(a,b){
if(b===0){
return a;
}else{
return gcd(b,a%b);
}
}
let mainGcd = gcd(x,y);
let result = ((x*y)/mainGcd);
while(true){
if(mainArr.every((value)=>result%value===0)){
return result;
}else{
result++;
}
}
};
So, This function take an array which have two number. I need to find their smallest common multiple number number. Also the number the number should be divisible by all number between those two number. This function work pretty well on my browser console like
if I pass smallestCommons([2,10])
it's return 2520
but I don’t understand why last problem didn’t pass. which is
smallestCommons([23,18])
well I run this problem on my browser console it show me correct answer which is 6056820. But This don’t pass in freecodecamp site. It’s show me a brown cross sign. Please someone tell me is there any issue in my code?