You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

28 lines
781 B

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;