UI for Zipcoin Blue

_baseOrderBy.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435
  1. var arrayMap = require('./_arrayMap'),
  2. baseIteratee = require('./_baseIteratee'),
  3. baseMap = require('./_baseMap'),
  4. baseSortBy = require('./_baseSortBy'),
  5. baseUnary = require('./_baseUnary'),
  6. compareMultiple = require('./_compareMultiple'),
  7. identity = require('./identity');
  8. /**
  9. * The base implementation of `_.orderBy` without param guards.
  10. *
  11. * @private
  12. * @param {Array|Object} collection The collection to iterate over.
  13. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  14. * @param {string[]} orders The sort orders of `iteratees`.
  15. * @returns {Array} Returns the new sorted array.
  16. */
  17. function baseOrderBy(collection, iteratees, orders) {
  18. var index = -1;
  19. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(baseIteratee));
  20. var result = baseMap(collection, function(value, key, collection) {
  21. var criteria = arrayMap(iteratees, function(iteratee) {
  22. return iteratee(value);
  23. });
  24. return { 'criteria': criteria, 'index': ++index, 'value': value };
  25. });
  26. return baseSortBy(result, function(object, other) {
  27. return compareMultiple(object, other, orders);
  28. });
  29. }
  30. module.exports = baseOrderBy;