Check if the given string is vowel prime | Function that returns true if c is a vowel ; Function that returns true if all the vowels in the given string are only at prime indices ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; 0 and 1 are not prime ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p greater than or equal to the square of it numbers which are multiple of p and are less than p ^ 2 are already been marked . ; For every character of the given string ; If current character is vowel and the index is not prime ; Driver code
function isVowel ( c ) { if ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) return true ; return false ; } function isVowelPrime ( str , n ) { var prime = Array ( n ) . fill ( true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( var p = 2 ; p * p < n ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * p ; i < n ; i += p ) prime [ i ] = false ; } } for ( var i = 0 ; i < n ; i ++ ) { if ( isVowel ( str [ i ] ) && ! prime [ i ] ) return false ; } return true ; } var str = " " ; var n = str . length ; if ( isVowelPrime ( str , n ) ) document . write ( " " ) ; else document . write ( " " ) ;