Skip to content

Instantly share code, notes, and snippets.

@gate5th
Created September 12, 2018 18:59
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 gate5th/cd85eef225c93aea477a0357a75b8a27 to your computer and use it in GitHub Desktop.
Save gate5th/cd85eef225c93aea477a0357a75b8a27 to your computer and use it in GitHub Desktop.
oldschoolshuffle
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment