The challenges here:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple
is to calculate the Smallest Common Multiple for a range of integers.
The brute force method is:
-
calculate an array of primes up to SQRT(top-of-range), presumably with Sieve of Eratosthenes - which I just coded in the previous challenge and have now deleted. Arrgh!
-
prime-factor each integer in the range
-
for each prime determine the max-exponent in the prime-factorization over all integers in the range.
-
calculate product over all primes raised to its calculated max-exponent.
Is there a better way? That seems a lot of coding for a mere challenge.
P.S.
One correction: the primes up to max are required, not just the primes up to sqrt(max) .