Different sort code produces different results


I have these two bits of code for sorting arrays.
The first one seems to not sort floats correctly.
which one is the correct way and why ?

array.sort(function(a, b)
	if (a> b) return -1;
	else if (a < b) return 1;
	else return 0;

array.sort(function(a, b)
	return b == a ? 0 : (b > a ? 1 : -1);


I tried it, and as far as I can tell, the two produce identical results. What’s an example of an array you’re trying to sort?


Perhaps a case where a is not greater than b, and a is not less than b, but a != b? Maybe they are dynamic, and not floats?