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