Skip to content

Commit

Permalink
Merge pull request jashkenas#1253 from braddunbar/sort-by
Browse files Browse the repository at this point in the history
Handle equal indices in _.sortBy.
  • Loading branch information
jashkenas committed Aug 11, 2013
2 parents d67868d + b3985b6 commit db588fa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@
var iterator = lookupIterator(value);
return _.pluck(_.map(obj, function(value, index, list) {
return {
value : value,
index : index,
criteria : iterator.call(context, value, index, list)
value: value,
index: index,
criteria: iterator.call(context, value, index, list)
};
}).sort(function(left, right) {
var a = left.criteria;
Expand All @@ -317,7 +317,7 @@
if (a > b || a === void 0) return 1;
if (a < b || b === void 0) return -1;
}
return left.index < right.index ? -1 : 1;
return left.index - right.index;
}), 'value');
};

Expand Down

0 comments on commit db588fa

Please sign in to comment.