Check whether all the substrings have number of vowels atleast as that of consonants | Function that returns true if character ch is a vowel ; Compares two integers according to their digit sum ; Check if there are two consecutive consonants ; Check if there is any vowel surrounded by two consonants ; Driver code
function isVowel ( ch ) { switch ( ch ) { case " " : case " " : case " " : case " " : case " " : return true ; } return false ; } function isSatisfied ( str , n ) { for ( var i = 1 ; i < n ; i ++ ) { if ( ! isVowel ( str [ i ] ) && ! isVowel ( str [ i - 1 ] ) ) { return false ; } } for ( var i = 1 ; i < n - 1 ; i ++ ) { if ( isVowel ( str [ i ] ) && ! isVowel ( str [ i - 1 ] ) && ! isVowel ( str [ i + 1 ] ) ) { return false ; } } return true ; } var str = " " ; var n = str . length ; if ( isSatisfied ( str . split ( " " ) , n ) ) document . write ( " " ) ; else document . write ( " " ) ;