Intermediate Algorithm Scripting: Smallest Common Multiple

I’ve submitted the following code for this challenge, but for some reason when I submit it the final test (smallestCommons([23, 18]) doesn’t pass. However, when I run this code in the console all of the expected results are returned. I don’t think it has anything to do with how I get my rangeArr into numerical order, because the code worked for the smallestCommons[5, 1]), which is out of order similar to the test that I’m failing.

Can anyone lend a helping hand as to why this is happening?

Thanks.

function smallestCommons(arr) {

let rangeArr = [];
for (let x = Math.min(…arr); x <= Math.max(…arr); x++) {
rangeArr.push(x);
}

let who = “”;
for (let x = 0; who == “”; x++) {
if (rangeArr.every(y => x % y == 0) == true) {
who = x;
}
}
return who;

}

Your algorithm is not efficient enough to avoid tripping the test suite’s infinite loop protection. You need to rethink your algorithm. All the challenges can be solved with an algorithm which does not cause the infinite loop protection to kick in.

Thanks for the feedback. It might help me if you could specify what part of the code is the culprit. I’m assuming it’s something to do with the for loop. Is it because the second portion of my for loop says who == “”, which in some cases could cause it to go on forever?

Neeeeevermind! I got it. The code would increment by too little. Thanks again.