Need help understanding this assignment I’ve spent so much time on this. I don’t know why I’m not getting it. It’s discouraging. Although I looked at the answers on the FreeCodeCamp, I still don’t seem to get it right. It says I can run on an infinite loop when passing the last test. Any help is much appreciated!
function smallestCommons(arr) {
let sortNums = arr.sort((a,b)=> a-b);
let smallNum = sortNums[0];
let bigNum = sortNums[1];
//let newArr=[];
/* while(smallNum <= bigNum){
newArr.push(smallNum);
smallNum++;
}*/
let scm = bigNum;
while(true){
let conditionIs = true;
for(let i= smallNum; i <= bigNum; i++){
if(scm % i !==0){
conditionIs = false;
break;
}
}
if (conditionIs){
return scm;
} else {
scm++;
}
}
}
console.log(smallestCommons([1,13]));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15
I think the number that is guaranteed to be multiple of every number is the highest of the two numbers we are provided in the array.
Thanks much @JeremyLT