- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Greatest number divisible by n within a bound in JavaScript
Problem
We are required to write a JavaScript function that takes in a number n and bound number b.
Our function should find the largest integer num, such that −
num is divisible by divisor
num is less than or equal to bound
num is greater than 0.
Example
Following is the code −
const n = 14; const b = 400; const biggestDivisible = (n, b) => { let max = 0; for(let j = n; j <= b; j++){ if(j % n == 0 && j > max){ max = j; }; } return max; }; console.log(biggestDivisible(n, b));
Output
392
Advertisements
To Continue Learning Please Login
Login with Google