text: Case | Function to return the sorted string ; Vectors to store the lowercase and uppercase characters ; Sort both the vectors ; If current character is lowercase then pick the lowercase character from the sorted list ; Else pick the uppercase character ; Return the sorted string ; Driver code
code: function getSortedString ( s , n ) { var v1 = [ ] ; var v2 = [ ] ; var i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) v1 . push ( s [ i ] ) ; if ( s [ i ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) v2 . push ( s [ i ] ) ; } console . log ( v1 ) ; v1 . sort ( ) ; v2 . sort ( ) ; var j = 0 ; i = 0 ; for ( var k = 0 ; k < n ; k ++ ) { if ( s [ k ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ k ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) { s [ k ] = v1 [ i ] ; ++ i ; } else if ( s [ k ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ k ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) { s [ k ] = v2 [ j ] ; ++ j ; } } return s . join ( " " ) ; } var s = " " ; var n = s . length ; document . write ( getSortedString ( s . split ( " " ) , n ) ) ;