Count of substrings consisting of even number of vowels | Utility function to check if a character is a vowel ; Function to calculate and return the count of substrings with even number of vowels ; Stores the count of substrings with even and odd number of vowels respectively ; Update count of vowels modulo 2 in sum to obtain even or odd ; Increment even / odd count ; Count substrings with even number of vowels using Handshaking Lemma ; Driver Code
function isVowel ( c ) { if ( c == ' ' c == ' ' c == ' ' c == ' ' c == ' ' ) return true ; return false ; } function countSubstrings ( s , n ) { let temp = [ 1 , 0 ] ; let result = 0 , sum = 0 ; for ( let i = 0 ; i <= n - 1 ; i ++ ) { sum += ( isVowel ( s [ i ] ) ? 1 : 0 ) ; sum %= 2 ; temp [ sum ] ++ ; } result += ( ( temp [ 0 ] * ( temp [ 0 ] - 1 ) ) / 2 ) ; result += ( ( temp [ 1 ] * ( temp [ 1 ] - 1 ) ) / 2 ) ; document . write ( result ) ; } let n = 5 ; let s = " " ; countSubstrings ( s , n ) ;