Tell us what’s happening:
For the last test case its giving potential loop warning in FCC editor, but when I do it browser console with the same code it gives me correct answer.
Your code so far
function smallestCommons(arr) {
var firstNumber,secondNumber;
if(arr[0]>arr[1]){
firstNumber = arr[1];
secondNumber = arr[0];
}
else {
firstNumber = arr[0];
secondNumber = arr[1];
}
var commonMultipleFound = false;
var commonMultiple = secondNumber;
while(!commonMultipleFound){
var count = 0;
for(var i=firstNumber; i<=secondNumber ; i++){
if(commonMultiple % i == 0)
count++;
}
if(count == (secondNumber - firstNumber + 1))
{
commonMultipleFound = true;
break;
}
else{
commonMultiple++;
}
}
console.log(commonMultiple);
return commonMultiple;
}
smallestCommons([23, 18]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.
Challenge: Smallest Common Multiple
Link to the challenge:
