[Solved] Assert fails but I get correct value localy - Stuck with Smallest Common Multiple

[UPDATE]Turns out I was failing asserts due to my code being inefficient and timing out the program as pointed out by @ArielLeslie and @snowmonkey however I am only able to choose one as the solution. I apreciate the help and guidance from both of you. [/UPDATE]

I have writen code that works when I run it on my machine as well as in codepen, it generates 6056820 when given [23,18] see Super Least Common Multiple - Codepen , the console reveals the correct answer given the input. However on FCC The Assert smallestCommons([23, 18]) should return 6056820. fails.

I don’t understand why it is failing when I get the correct output. Could anyone point me in the right direction?

You are probably timing out. To protect novice coders from crashing their browsers with infinite loops, FCC impliments a time limit on challenges. If a solution is inefficient it is possible that it takes long enough to complete that FCC thinks an infinite loop has been created and the execution is aborted.

1 Like

Thank you, that totally makes sense now that you bring it up. Certianly my solution was long and convoluted so I just wrote a new version that is only 21 lines long without all the primes stuff and I continue to not pass that assert , please look at my new version of the code Simplified Version - 21 lines

1 Like

So I changed the line you are using to call your test to this:

console.time("smallest commons");
smallestCommons([23,18]);
console.timeEnd("smallest commons");

Take a look at that in the console – it’ll show you how long your calculation is taking. In this particular case, the amount of time is getting excessive for larger numbers.

1 Like

Wow thank you @snowmonkey for introducing me to console.time, I will have to use that from now on. Now I can see that even my simplified version takes 1332.665771484375ms lol.

This fully explains why I am failing the last two asserts. I appreciate the feedback from you both and now have the tools necessary to finally complete this challenge.

1 Like

Take a look at this post, and particularly the article it mentions. Most folks don’t really get how much power we have with the console!

1 Like