If array is reversed print ans [ ] in reverse
if ( rev ) { for ( let i = n - 1 ; i >= 0 ; i -- ) { document . write ( ans [ i ] + " " ) ; } } else { for ( let i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } }