Else store the indices and values at those indices in a map and finainty print them
else { let mpp = new Map ( ) ; let j = 1 ; let value_at_index = [ ] ; for ( let x1 = 0 ; x1 < ans . length ; x1 ++ ) { mpp . set ( ans [ x1 ] , j ) ; ++ j ; } for ( let x2 = 0 ; x2 < anss . length ; x2 ++ ) { value_at_index . push ( mpp . get ( anss [ x2 ] ) ) ; } for ( let x3 = 0 ; x3 < value_at_index . length ; x3 ++ ) { document . write ( value_at_index [ x3 ] + " " ) ; } document . write ( " " ) ; } }