Swap any occurrence of the minimum element with the last element
for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == minVal ) { [ arr [ i ] , arr [ n - 1 ] ] = [ arr [ n - 1 ] , arr [ i ] ] ; break ; } }