Skip to content

Instantly share code, notes, and snippets.

@lanqy

lanqy/gist:4975044

Last active Dec 13, 2015
Embed
What would you like to do?
sort
//http://stackoverflow.com/questions/979256/how-to-sort-an-array-of-javascript-objects
// demo http://jsfiddle.net/dFNva/1/
var sort_by = function(field, reverse, primer){
var key = function (x) {return primer ? primer(x[field]) : x[field]};
return function (a,b) {
var A = key(a), B = key(b);
return ((A < B) ? -1 :
(A > B) ? +1 : 0)) * [-1,1][+!!reverse];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.