min and max simultaneously I have two numbers: a and b. I want to put the smaller of them in one variable, and the larger in another variable (if they are equal, then any of them can be in any of the variables). Currently my code (in Javascript / Java) takes 7 lines:

if (a&lt;=b) {
    small = a;
    large = b;
} else {
    small = b;
    large = a;
}


I could also use the Math.max and Math.min functions:

small = Math.min(a,b);
large = Math.max(a,b);


This takes only 2 lines but it is wasteful because the test of which one is larger will be done twice - once in Math.min and once in Math.max.

Is there a shorter / more elegant way to do this?
int t = a + b;
a = a &gt; b ?  t - a : a;
b = t - a;
// a is the small one


Or 

small = a;
large = b;
if (a&gt;b) {
  small = b;
  large = a;
} 


But I think it will be shorter in Python:

if a &gt; b:
   a, b = b, a