Check if the string satisfies the given condition | Function that returns true if n is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function that returns true if c is a vowel ; Function that returns true if the count of vowels in word is prime ; If count of vowels is prime ; Driver code
function prime ( 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 isVowel ( c ) { c = c . toLowerCase ( ) ; if ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) { return true ; } return false ; } function isValidString ( word ) { let cnt = 0 ; for ( let i = 0 ; i < word . length ; i ++ ) { if ( isVowel ( word [ i ] ) ) { cnt ++ ; } } if ( prime ( cnt ) ) { return true ; } else { return false ; } } let s = " " ; if ( isValidString ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;