= 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
/* next line works with strings and numbers,
* and you may want to customize it to your needs
*/
// var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
var result = a[property].localeCompare(b[property]);
return result * sortOrder;
}
}
temp1.sort(dynamicSort('city'));
// multiply sort
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
/* next line works with strings and numbers,
* and you may want to customize it to your needs
*/
var result = a[property].localeCompare(b[property]);
return result * sortOrder;
}
}
People.sort(dynamicSortMultiple("Name", "-Surname"));
Object.defineProperty(Array.prototype, "sortBy", {
enumerable: false,
writable: true,
value: function() {
return this.sort(_dynamicSortMultiple.apply(null, arguments));
}
});
People.sortBy("Name", "-Surname");
Только тут нету dynamicSortMultiple ))) upd Нашел на стаковерфлоу)
я про это
Обсуждают сегодня