This commit is contained in:
28
node_modules/licia/sortBy.js
generated
vendored
Normal file
28
node_modules/licia/sortBy.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
var safeCb = require('./safeCb');
|
||||
var pluck = require('./pluck');
|
||||
var map = require('./map');
|
||||
var isUndef = require('./isUndef');
|
||||
exports = function(obj, iteratee, ctx) {
|
||||
iteratee = safeCb(iteratee, ctx);
|
||||
var idx = 0;
|
||||
return pluck(
|
||||
map(obj, function(val, key) {
|
||||
return {
|
||||
val: val,
|
||||
idx: idx++,
|
||||
criteria: iteratee(val, key, obj)
|
||||
};
|
||||
}).sort(function(left, right) {
|
||||
var a = left.criteria;
|
||||
var b = right.criteria;
|
||||
if (a !== b) {
|
||||
if (a > b || isUndef(a)) return 1;
|
||||
if (a < b || isUndef(b)) return -1;
|
||||
}
|
||||
return left.idx - right.idx;
|
||||
}),
|
||||
'val'
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = exports;
|
||||
Reference in New Issue
Block a user