documentcloud/underscore — pull request #534 by chris-baynes (2012-03-31 09:27:45+00:00)
Title: Allow for better handling of undefined values in sortBy.

The current implementation of sortBy breaks when the result of the iterator call is `undefined`.

var obj = [undefined, 4, 1, undefined, 3, 2];
_.sortBy(obj, function(i) { return i; })
=> [undefined, 1, 4, undefined, 2, 3]

The attached code collects the `undefined` values at the end of the result.

=> [1, 2, 3, 4, undefined, undefined]

This also agrees with the standard sort handling of `undefined` as described here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort