JSFiddle - React, Tailwind, and code Playground

by Gabriel Vazquez

JavaScript

/**
 * 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
 * What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
 */

const main = (limit) => {
  let minimumDenominator;
  let n = 1;
  do {
    let matching = 0;
    for (let d = 1; d <= limit; d++) {
      if (!(n % d)) {
        matching += 1;
      } else {
        break;
      }
    }
    if (matching === limit) {
      minimumDenominator = n;
    }
    n++;
  } while(!minimumDenominator);
  return minimumDenominator;
}

console.log('limit', main(20));