

- 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
Finding the count of numbers divisible by a number within 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
- Related Questions & Answers
- Finding sum of all numbers within a range in JavaScript
- Finding sequential digit numbers within a range in JavaScript
- Finding the count of total upside down numbers in a range using JavaScript
- Greatest number divisible by n within a bound in JavaScript
- Prime numbers within a range in JavaScript
- Python - Find the number of prime numbers within a given range of numbers
- Count the numbers divisible by ‘M’ in a given range in C++
- Finding a pair that is divisible by some number in JavaScript
- Armstrong number within a range in JavaScript
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- Count numbers in a range that are divisible by all array elements in C++
- Summing cubes of natural numbers within a range in JavaScript
- Finding the least common multiple of a range of numbers in JavaScript?
- Counting prime numbers that reduce to 1 within a range using JavaScript
Advertisements