# [smallestCommonMultiple]my code works but the infinite loop detector is detecting it

the infinite loop detector is finding my code to be bad.
when it takes large numbers it iterates a lot thus tests fail
i checked this and it works for [1,13] in online nodejs compiler

``````function flip(arr){
let result = []
for(let i=arr.length-1;i>=0;i--){
result.push(arr[i])
} return result }
function expand(arr){
let result =[]
for(let i=arr;i<=arr;i++){
result.push(i)
} return result }
function symGetLCM(num1, num2){
if(num1==num2){return num1}
let arr1 = []
let arr2 = []
let stopWhen = 2
for(let i=1;i<stopWhen;i++){
arr1.push(num1*i)
arr2.push(num2*i)
if(num1>num2){
if(arr1.includes(arr2[arr2.length-1])){
return arr2[arr2.length-1]}
else{stopWhen++}}
else{
if(arr2.includes(arr1[arr1.length-1])){
return arr1[arr1.length-1]}
else{stopWhen++}}
}
}
function smallestCommons(arr) {
if(arr>arr){arr = flip(arr)}
arr = expand(arr)
let result = symGetLCM(arr,arr)
for(let i=2;i<arr.length;i++){
result = symGetLCM(result,arr[i])
} return result
}
``````

this is the section

i think this was meant to be a feature but now its a bug

It is an indication that your solution is too slow. You need to look for ways to make your solution less inefficient.

1 Like