- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are required to write a JavaScript function that takes in a number n. Our function should find and return that smallest possible number which is divisible by all numbers from 1 to n.

Following is the code −

const num = 11; const smallestDivisible = (num = 1) => { let res = num * (num - 1) || 1; for (let i = num - 1; i >= 1; i--) { if (res % i) { for (let j = num - 1; j >= 1; j--) { if (!(i % j) && !(res % j)) { res = i * res / j; break; } } } } return res; } console.log(smallestDivisible(num));

27720

- Related Questions & Answers
- Smallest number that is divisible by first n numbers in JavaScript
- Count pairs of numbers from 1 to N with Product divisible by their Sum in C++
- Count n digit numbers divisible by given number in C++
- Largest N digit number divisible by given three numbers in C++
- Find kth smallest number in range [1, n] when all the odd numbers are deleted in C++
- Compute sum of digits in all numbers from 1 to n
- Greatest number divisible by n within a bound in JavaScript
- Program to find all missing numbers from 1 to N in Python
- Count numbers in range 1 to N which are divisible by X but not by Y in C++
- Count numbers which are divisible by all the numbers from 2 to 10 in C++
- Generating a random number that is divisible by n in JavaScript
- Program to find duplicate element from n+1 numbers ranging from 1 to n in Python
- Count of pairs from 1 to a and 1 to b whose sum is divisible by N in C++
- N digit numbers divisible by 5 formed from the M digits in C++
- Number of pairs from the first N natural numbers whose sum is divisible by K in C++

Advertisements