Logo

Programming-Idioms

History of Idiom 28 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-04-07, 14:13:35

Version 4

2015-04-21, 07:25:25

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