Sort a string without altering the position of vowels | Function to sort the string leaving the vowels unchanged ; Length of string S ; Traverse the string S ; Sort the string temp ; Pointer to traverse the sorted string of consonants ; Traverse the string S ; Driver Code
function sortStr ( str ) { var S = str . split ( ' ' ) ; var N = S . length ; var temp = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' ) temp . push ( S [ i ] ) ; } if ( temp . length != 0 ) temp . sort ( ) ; var ptr = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' ) S [ i ] = temp [ ptr ++ ] ; } var str = " " ; for ( var i = 0 ; i < S . length ; i ++ ) str += S [ i ] ; document . write ( str ) ; } var S = " " ; sortStr ( S ) ;