JSFiddle - React, Tailwind, and code Playground
by scaillerie
JavaScript
var allnumbers = [],
j;
var biggestnumber = "999999999999999999999999999999999999999999999999999999999999";
function howmanynumbers(digits, numbers, divideWith) {
var min = 1+Number(biggestnumber.substring(0,digits - 1));
var max = 1 + Number(biggestnumber.substring(0, digits));
var count = 0,
regex = new RegExp("^[" + numbers.join("") + "]+$", "i");
if (digits && numbers && divideWith) {
// Loop through all numbers divisible by "divideWith"
for (var num = min; num < max; num += divideWith) {
// If the number is divisible and that all its digits are corrects
if (regex.test(num + "")) count++;
}
return count;
}
else {
return false;
}
}
console.log(howmanynumbers(6, [0, 1, 2, 3, 4, 5], 6));