Substring Reverse Pattern | Function to print the required pattern ; Print the unmodified string ; Reverse the string ; Replace the first and last character by ' * ' then second and second last character and so on until the string has characters remaining ; Driver code
function printPattern ( s , n ) { document . write ( s . join ( ' ' ) + " " ) ; var i = 0 , j = n - 1 ; while ( i < j ) { var c = s [ i ] ; s [ i ] = s [ j ] ; s [ j ] = c ; i ++ ; j -- ; } i = 0 ; j = n - 1 ; while ( j - i > 1 ) { s [ i ] = s [ j ] = ' ' ; document . write ( s . join ( ' ' ) + " " ) ; i ++ ; j -- ; } } var s = " " . split ( ' ' ) ; var n = s . length ; printPattern ( s , n ) ;