Last active
August 29, 2015 14:04
-
-
Save lovecn/c377a606ae578a89b8a5 to your computer and use it in GitHub Desktop.
对二维数组求平均值排序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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