1

对象数组的快速排序

var qSort = function(arr,key){
    if(arr.length <= 1){return arr;}
    var left = [],
        right = [],
        _index = Math.floor(arr.lenght / 2),
        _m = arr.splice(_index, 1)[0];
    for(var i=0,len=arr.length;i<len;i++){
        if(!key && ((arr[i] < _m) || (arr[i] == _m && i < _index)) || (key && ((arr[key] < _m[key]) || (arr[i][key] == _m[key] && i < _index)))){
              left.push(arr[i]);
          }
        }else{
              right.push(arr[i]);
        }
    return qSort(left,key).concat([_m],qSort(right,key));
};

zasqw2222
132 声望2 粉丝

苦苦的慢慢的爬行!