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