Suggestion to improve Smallest Common Multiple challenge

The Smallest Common Multiple challenge in the JavaScript Intermediate Algorithm Scripting unit seems a bit much for a mathematically unsophisticated group. I eventually solved it in about 90 minutes as described here but it ends up being 60 lines of qquite tight, mathematically sophisticated code.

Further, students attempting to solve it by valid yet inefficient loops simply struggle with trying to get their browser limits on JavaScript lifted. This seems a waste of learning effort.

I subsequently realized there is an efficient simple algorithm utilizing properties of the Greatest Common Divisor, as I noted here. Reproduced:

  1. Write a Greatest Common Divisor function GCD(a,b) .
  2. Note that the Smallest Common Multiple (SCM) of any two numbers a and b is the value: a * b / GCD(a,b) .
  3. Calculate the SCM for the first two numbers of the range; then successively calculate the SCM for that value plus the next value in the range until you hit the end of the range.

I suggest that the challenge be:

  1. Immediately preceded by a Write a GCD function challenge;
  2. Be pre-populated with the GCD function just written by the student; and
  3. Be supplemented with my algorithm note above (or at least the comment

Note that the Smallest Common Multiple (SCM) of any two numbers a and b is the value:
a * b / GCD(a,b)

I believe this would be far more valuable to students than the existing challenge structure.

1 Like

I used the greatest tool of all developers: Google. I typed in “least common multiple” and skimmed the top result (Wikipedia), which gave me the approach described above, so writing the solution became an exercise in translating an algorithm written in mathematical notation to one written in JavaScript.

This is just one person’s opinion, but I don’t think that this challenge is too demanding. One of the objections I have to most online coding education platforms is that they hold your hand to the point that you don’t actually learn much more than syntax. FCC is ramping students up into pretty difficult projects, and as the challenges progress they require not just more logical problem solving but also practical problem solving in the form of research. It is not uncommon for some of the more advanced challenges to take hours or even for students to find that they need to walk away from it and come back again.

Yes, having to work though a math-based challenge when you do not have a lot of experience or confidence in math is frustrating, but it’s a very realistic frustration that is part of this field and something that we need to know how to work though in order to work independently.

1 Like


Fair enough.

This would not be the first time I knew too much math - and initially used the wrong math for a problem.

After first solving this challenge on Friday evening, I was motivated to revisit it by a question on this site by a student who was struggling with time-out crashes in his browser. Since prime factorization is (I believe) far better known than the Euclidean algorithm for calculating GCD, that student may not be the only one to fall into the trap.

FWIW: Once I got past my muttering, the challenge of solving this challenge using prime factorization ended up being quite enjoyable - creating a solution that is almost as efficient as the GCD method.

I think that this challenge is one of the ones that gives that great “I defeated it” satisfaction. :smiley:

1 Like