Skip to content

Instantly share code, notes, and snippets.

@lovecn
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovecn/c377a606ae578a89b8a5 to your computer and use it in GitHub Desktop.
Save lovecn/c377a606ae578a89b8a5 to your computer and use it in GitHub Desktop.
对二维数组求平均值排序
Array.prototype.sum=function(){
var num=0;
for(var i=0;i<this.length;i++){
num+=this[i];
}
return num;
}
function vhall_sort(arr){
arr.sort(function(a,b){
return a.sum()/a.length-b.sum()/b.length;
});
}
arr = [[1,2],[5,1],[3,2]];
vhall_sort(arr);
console.log(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment