Tell us what’s happening:
Although its returning correct value in console but its not passing the two test cases.
smallestCommons([23, 18])
smallestCommons([1, 13])
Your code so far
function smallestCommons(arr) {
if(arr[1]>arr[0]){
return compaare(arr[0],arr[1])
}else{
return compaare(arr[1],arr[0])
}
}
function compaare(x,y){
let i = x ;
while(true){
// debugger;
if(i%x==0 && i%y==0){
let j=0;
for(j=x+1;j<y;j++){
if(i%j!=0){
i++;
break;
}
}
if(j==y){
console.log(i);
return i;
}
}else{
i++;
}
}
}
smallestCommons([1,13]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple/