|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = sortBy;
-
- var _arrayMap = require('lodash/_arrayMap');
-
- var _arrayMap2 = _interopRequireDefault(_arrayMap);
-
- var _baseProperty = require('lodash/_baseProperty');
-
- var _baseProperty2 = _interopRequireDefault(_baseProperty);
-
- var _map = require('./map');
-
- var _map2 = _interopRequireDefault(_map);
-
- var _wrapAsync = require('./internal/wrapAsync');
-
- var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
-
- function sortBy(coll, iteratee, callback) {
- var _iteratee = (0, _wrapAsync2.default)(iteratee);
- (0, _map2.default)(coll, function (x, callback) {
- _iteratee(x, function (err, criteria) {
- if (err) return callback(err);
- callback(null, { value: x, criteria: criteria });
- });
- }, function (err, results) {
- if (err) return callback(err);
- callback(null, (0, _arrayMap2.default)(results.sort(comparator), (0, _baseProperty2.default)('value')));
- });
-
- function comparator(left, right) {
- var a = left.criteria,
- b = right.criteria;
- return a < b ? -1 : a > b ? 1 : 0;
- }
- }
- module.exports = exports['default'];
|