
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Count Numbers Divisible by a Given Number in a Range using JavaScript
Problem
We are required to write a JavaScript function that takes in a range of two integers as the first argument and a number as the second argument.
Our function should find all the numbers divisible by the input number in the specified range and return their count.
Example
Following is the code −
const range = [6, 57]; const num = 3; const findDivisibleCount = (num = 1, [l, h]) => { let count = 0; for(let i = l; i <= h; i++){ if(i % num === 0){ count++; }; }; return count; }; console.log(findDivisibleCount(num, range));
Output
18
Advertisements