Replace the first and last character by ' * ' then second and second last character and so on until the string has characters remaining
i = 0 ; j = n - 1 ; while ( j - i > 1 ) { s [ i ] = s [ j ] = ' ' ; document . write ( s . join ( ' ' ) + " " ) ; i ++ ; j -- ; } }