Modify the string by swapping continuous vowels or consonants | Function to check if a character is a vowel ; Function to swap two consecutively repeated vowels or consonants ; Traverse through the length of the string ; Check if the two consecutive characters are vowels or consonants ; swap the two characters ; Driver code
function isVowel ( c ) { c = c . toLowerCase ( ) ; if ( c === " " c === " " c === " " c === " " c === " " ) { return true ; } return false ; } function swapRepeated ( str ) { for ( var i = 0 ; i < str . length - 1 ; i ++ ) { if ( ( isVowel ( str [ i ] ) && isVowel ( str [ i + 1 ] ) ) || ( ! isVowel ( str [ i ] ) && ! isVowel ( str [ i + 1 ] ) ) ) { var c = str [ i ] ; str [ i ] = str [ i + 1 ] ; str [ i + 1 ] = c ; } } return str . join ( " " ) ; } var str = " " ; document . write ( swapRepeated ( str . split ( " " ) ) ) ;