Programming-Idioms

History of Idiom 28 > diff from v3 to v4

Edit summary for version 4 :

Version 3

Version 4

Idiom #28 Sort by a property

Sort items x of array-like collection items in ascending order of x.p, where p is a field of type Item of the objects in items.

Idiom #28 Sort by a property

Sort items x of array-like collection items in ascending order of x.p, where p is a field of type Item of the objects in items.

Code
items.sort(function(a,b) {
  return compareFieldP(a.p, b.p);
});
Comments bubble
Implements your own compareFieldP depending on the type of p.
Origin
http://stackoverflow.com/a/979289/871134