Check if sum of count of digits of array elements is Prime or not | Function to check whether a number is prime or not ; Corner cases ; If given number is a multiple of 2 or 3 ; Function to check if sum of count of digits of all array elements is prime or not ; Initialize sum with 0 ; Traverse over the array ; Convert array element to string ; Add the count of digits to sum ; Print the result ; Drive Code ; Function call
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function CheckSumPrime ( A , N ) { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let s = new String ( A [ i ] ) ; sum += s . length ; } if ( isPrime ( sum ) ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } let A = [ 1 , 11 , 12 ] ; let N = A . length CheckSumPrime ( A , N ) ;