JSFiddle - React, Tailwind, and code Playground

by scaillerie

JavaScript

var allnumbers = [],
    j;
var biggestnumber = "999999999999999999999999999999999999999999999999999999999999";

function howmanynumbers(digits, numbers, divideWith) {
    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 = 0; num < max; num += divideWith) {
            // If the number is divisible and that all its digits are corrects
            if (regex.test(num + "")) count++;
        }
        console.log(count);
    }
    else {
        return false;
    }
}

howmanynumbers(6, [0, 1, 2, 3, 4, 5], 6);