No Description

sortBy.js 709B

1234567891011121314151617181920212223242526
  1. define(['./_cb', './pluck', './map'], function (_cb, pluck, map) {
  2. // Sort the object's values by a criterion produced by an iteratee.
  3. function sortBy(obj, iteratee, context) {
  4. var index = 0;
  5. iteratee = _cb(iteratee, context);
  6. return pluck(map(obj, function(value, key, list) {
  7. return {
  8. value: value,
  9. index: index++,
  10. criteria: iteratee(value, key, list)
  11. };
  12. }).sort(function(left, right) {
  13. var a = left.criteria;
  14. var b = right.criteria;
  15. if (a !== b) {
  16. if (a > b || a === void 0) return 1;
  17. if (a < b || b === void 0) return -1;
  18. }
  19. return left.index - right.index;
  20. }), 'value');
  21. }
  22. return sortBy;
  23. });