gistfile1.txt function sortArrByAttr (array, attr, bool) { function compare(attr){ return function(obj1,obj2){ if (attr === 'time') { var value1 = parseInt(obj1[attr].replace(/\D/g, '')); var value2 = parseInt(obj2[attr].replace(/\D/g, ''))
function sortArrByAttr (array, attr, bool) { function compare(attr){ return function(obj1,obj2){ if (attr === 'time') { var value1 = parseInt(obj1[attr].replace(/\D/g, '')); var value2 = parseInt(obj2[attr].replace(/\D/g, '')); // bool 为 true,时间正序排列 return bool ? value1 - value2 : value2 - value1; } else { } } } return array.sort(compare(attr));; }