Count of prime digits of a Number which divides the number | Function to find the number of digits in number which divides the number and is also a prime number ; Only 2 , 3 , 5 and 7 are prime one - digit number ; Loop to compute all the digits of the number untill it is not equal to the zero ; Fetching each digit of the number ; Checking if digit is greater than 0 and can divides n and is prime too ; Driven Code
function countDigit ( n ) { var prime = Array ( 10 ) . fill ( false ) ; prime [ 2 ] = prime [ 3 ] = true ; prime [ 5 ] = prime [ 7 ] = true ; var temp = n , count = 0 ; while ( temp != 0 ) { var d = temp % 10 ; temp = parseInt ( temp / 10 ) ; if ( d > 0 && n % d == 0 && prime [ d ] ) count ++ ; } return count ; } n = 1032 ; document . write ( countDigit ( n ) ) ;