Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
比较大小
//老记混顺序,特此整理一下
function cmp(a, b){
//a 在前-1,a 在后1
if(a<b) return 1; //a小于b的情况下,a在后
if(a>b) return -1;//a大于b的情况下,a在前
return 0;
}
var a=[1,10,5,9,2];
console.log(a.sort(cmp));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment