Function to count how many numbers are there with the digits and division value specified
<p>I started making a function that will be able do the following: <em>Count how many 6 digit numbers you can make with the digits 0,1,2,3,4 and 5, that can be divided by 6?</em></p>

<p>How I currently try to start, is I make an array of all the possible numbers, then take out every number that has any of the <code>numbers</code>' arrays elements in it, then remove the ones that are not dividable with 6. </p>

<p>I got stuck at the second part. I tried making 2 loops to loop in the array of <code>numbers</code>, then inside that loop, create an other one for the length of the <code>allnumbers</code> array to remove all matches.</p>

<p>Then I would use the <code>%</code> operator the same way to get every element out that doesn't return 0.</p>

<p>The code needs to be flexible. If the user asks for eg. digit 6 too, then the code should still work. Any way I could finish this?</p>

<p>My Code is:</p>

<pre><code>var allnumbers = [],j;
var biggestnumber = "999999999999999999999999999999999999999999999999999999999999";

function howmanynumbers(digits,numbers,divideWith){
    if (digits &amp;&amp; numbers &amp;&amp; divideWith){
        for (var i = 0; i &lt; 1+Number(biggestnumber.substring(0,digits)); i++ ){
            allnumbers.push(i);
        }

        for (j = 0; j &lt; numbers.length; j++ ){
            var matchit = new RegExp(numbers[j]);
        }
            //not expected to work, I just had this in for reference
        if ( String(allnumbers[i]).match(matchit) != [""]){
            j = 0;
            allnumbers.splice(i,1);
            var matchit = new RegExp(numbers[j])
        }
    }
    else {
        return false;
    }
}
</code></pre>
