Count of adjacent Vowel Consonant Pairs | Function to count the adjacent pairs of consonant and vowels in the String ; Using a set to store the vowels so that checking each character becomes easier ; Variable to store number of consonant - vowel pairs ; If the ith character is not found in the set , means it is a consonant And if the ( i + 1 ) th character is found in the set , means it is a vowel We increment the count of such pairs ; Driver Code
function countPairs ( s ) { let st = new Set ( ) ; st . add ( ' ' ) ; st . add ( ' ' ) ; st . add ( ' ' ) ; st . add ( ' ' ) ; st . add ( ' ' ) ; let count = 0 ; let n = s . length ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( st . has ( s [ i ] ) && ! st . has ( s [ i + 1 ] ) ) count ++ ; } return count ; } let s = " " ; document . write ( countPairs ( s ) ) ;