Given an integer n, how to identify each of the digits that are are part of n. (Example, n = 479, got 4 separately, 7 separately and 9 separately to work with them).

A solution in languages like c++ or even c, could be found by using a bitwise AND operator and make a bit to bit masking, but in javascript, things work a bit different, so this solution considers low level algorithm using modules and power of 10, since we are working with decimas. (and no use of array iterators).

taking the 1st power of 10, we obtain 10, also 10 to the power of 0, gives us 1, so if compute n module of each of those numbers ( where n > 0 and integer), we obtain the residue, and substracting, and dividing, we obtain the number required.

The following code, considers a regular for loop, from 0 to the size of n, with increments of 1.

const n = 479;
let x = 0;
x = ( (n % Math.pow(10, i+1)) - (n % Math.pow(10, i) ) / Math.pow(10,i);

Now, wen can actually use each digit to calculate the module in which the original number n, is divisible by the resultant digit, like this:

function digitsDivisible(n) {
    let size1 = n.toString().length;
    let count = 0;
    let x = 0;
    for (let i = 0; i < size1; i++) {
        x = (((n % Math.pow(10, i+1)) - (n % Math.pow(10, i)))/Math.pow(10,i));
        if ( x > 0) {
            if (n % x == 0) {
                count++;
            }
        }
    }
    
    return count;
}

By davs