Reverse the given string in the range [ L , R ] | Function to return the string after reversing characters in the range [ L , R ] ; Invalid range ; While there are characters to swap ; Swap ( str [ l ] , str [ r ] ) ; Driver code
function reverse ( str , len , l , r ) { if ( l < 0 r >= len l > r ) return " " ; while ( l < r ) { let c = str [ l ] ; str [ l ] = str [ r ] ; str [ r ] = c ; l ++ ; r -- ; } return str . join ( " " ) ; } let str = " " ; let len = str . length ; let l = 5 , r = 7 ; document . write ( reverse ( str . split ( ' ' ) , len , l , r ) ) ;