Modify string by rearranging vowels in alphabetical order at their respective indices | Function to arrange the vowels in sorted order in the string at their respective places ; Store the size of the string ; Stores vowels of string S ; Traverse the string , S and push all the vowels to string vow ; If vow is empty , then print S and return ; Sort vow in alphabetical order ; Traverse the string , S ; Replace S [ i ] with vow [ j ] iif S [ i ] is a vowel , and increment j by 1 ; Print the string ; Driver Code
function sortVowels ( S ) { var n = S . length ; var vow = " " ; for ( var i = 0 ; i < n ; i ++ ) { if ( S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' ) { vow += S [ i ] ; } } if ( vow . length == 0 ) { document . write ( S ) ; return ; } vow = vow . split ( ' ' ) . sort ( ) ; var j = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' S [ i ] == ' ' ) { S [ i ] = vow [ j ++ ] ; } } document . write ( S . join ( ' ' ) ) ; } var S = " " . split ( ' ' ) ; sortVowels ( S ) ;