Tell us what’s happening:
my function passes all the tests except the last two, which happen to contain much larger integers resulting in larger loops. The error that i’m getting when i run the function with these arguments - [1, 13] or [23, 18] in repl.it is that there is a potential infinite loop? Does anyone know why this is happening, and could it be that the test suites cap loops to a maximum iterations before they’ll throw a potential infinite loop warning, even if eventually the function would return and the loop would stop?
Your code so far
function smallestCommons(arr) {
let sorted = arr.sort((a, b) => a-b)
let s = sorted[0]
let b = sorted[1]
let target = (b-s)+1
for(let c = b*2; c; c++){
let count = 0
for(let i = s; i <= b; i++){
if(!(c%i)){
count++
}
if(count == target){
return c
}
}
}
}
console.log(smallestCommons([1,5]));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple