Smallest Common multiples

Tell us what’s happening:
Describe your issue in detail here.
Hello
This is code from the solution of this challenge. I can’t quite understand the const numberDivisors part on line 4. What’s the purpose of that

  **Your code so far**
function smallestCommons(arr) {
  // Setup
  const [min, max] = arr.sort((a, b) => a - b);
  const numberDivisors = max - min + 1;
  // Largest possible value for SCM
  let upperBound = 1;
  for (let i = min; i <= max; i++) {
    upperBound *= i;
  }
  // Test all multiples of 'max'
  for (let multiple = max; multiple <= upperBound; multiple += max) {
    // Check if every value in range divides 'multiple'
    let divisorCount = 0;
    for (let i = min; i <= max; i++) {
      // Count divisors
      if (multiple % i === 0) {
        divisorCount += 1;
      }
    }
    if (divisorCount === numberDivisors) {
      return multiple;
    }
  }
}

smallestCommons([1, 5]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1

Challenge: Smallest Common Multiple

Link to the challenge:

The spec requires that all the numbers between the given numbers, sequentially, divide into the result. numberDivisors is how many such numbers there are between the minimum and maximum, inclusive, in the provided array.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.