Put spaces between words starting with capital letters | Function to amend the sentence ; Traverse the string ; Convert to lowercase if its an uppercase character ; Print space before it if its an uppercase character ; Print the character ; if lowercase character then just print ; Driver Code
function amendSentence ( sstr ) { let str = sstr . split ( ' ' ) ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] . charCodeAt ( ) >= ' ' . charCodeAt ( ) && str [ i ] . charCodeAt ( ) <= ' ' . charCodeAt ( ) ) { str [ i ] = String . fromCharCode ( str [ i ] . charCodeAt ( ) + 32 ) ; if ( i != 0 ) document . write ( " " ) ; document . write ( str [ i ] ) ; } else document . write ( str [ i ] ) ; } } let str = " " ; amendSentence ( str ) ;