merging #532 -- allow string as iterator on sortBy

This commit is contained in:
Jeremy Ashkenas
2012-04-02 13:46:49 -04:00
2 changed files with 6 additions and 1 deletions

View File

@@ -262,7 +262,8 @@
};
// Sort the object's values by a criterion produced by an iterator.
_.sortBy = function(obj, iterator, context) {
_.sortBy = function(obj, val, context) {
var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
return _.pluck(_.map(obj, function(value, index, list) {
return {
value : value,