jashkenas/underscore — pull request #1815 by krawaller (2014-08-29 12:11:17+00:00)
Title: another take at allowing for array of iteratees in sortBy

This pull request takes another stab at the enhancement of `sortBy` that was suggested in #1359, namely allowing an entry of iteratees. This implementation complements #1359 so that each entry in the iteratees array is run through `_.iteratee`, so it can contain both property names and functions.

Here's a silly example sorting on both `name` and `age` (but using a function for the latter):

```
var people = [{name : 'curly', age : 50},{name: 'moe', age: 30},{name : 'curly', age : 27}];
_.sortBy(people, ['name',function(p){return p.age;}] );
// => [{name : 'curly', age : 27},{name : 'curly', age : 50},{name: 'moe', age: 30}];
```

I've toyed with some different approaches to this problem, including what's been suggested in #1751, and I think this is the most intuitive answer. Although it doesn't directly cover all use cases for the #1751 version, such as @megawac 's semver example:

```
var versions = ["0.1", "0.1.1", "2.0", "10.1", "6.2", "2.0.1", "1.7.3", "1.10.2", "0.2.0", "0.3.0", "0.6.0", "1.0.0"];
_.sortBy(versions, function(version) {
return _.map(version.split("."), _.partial(parseInt, _, 10));
});
// => ["0.1", "0.1.1", "0.2.0", "0.3.0", "0.6.0", "1.0.0", "1.7.3", "1.10.2", "2.0", "2.0.1", "6.2", "10.1"]
```

Catering to that too would be nice, but I suspect simply sorting on multiple fields is by far the most common use case.