react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / collection / sortByOrder.js
80742 viewsvar baseSortByOrder = require('../internal/baseSortByOrder'),1isArray = require('../lang/isArray'),2isIterateeCall = require('../internal/isIterateeCall');34/**5* This method is like `_.sortByAll` except that it allows specifying the6* sort orders of the iteratees to sort by. A truthy value in `orders` will7* sort the corresponding property name in ascending order while a falsey8* value will sort it in descending order.9*10* If a property name is provided for an iteratee the created `_.property`11* style callback returns the property value of the given element.12*13* If an object is provided for an iteratee the created `_.matches` style14* callback returns `true` for elements that have the properties of the given15* object, else `false`.16*17* @static18* @memberOf _19* @category Collection20* @param {Array|Object|string} collection The collection to iterate over.21* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.22* @param {boolean[]} orders The sort orders of `iteratees`.23* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.24* @returns {Array} Returns the new sorted array.25* @example26*27* var users = [28* { 'user': 'fred', 'age': 48 },29* { 'user': 'barney', 'age': 34 },30* { 'user': 'fred', 'age': 42 },31* { 'user': 'barney', 'age': 36 }32* ];33*34* // sort by `user` in ascending order and by `age` in descending order35* _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values);36* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]37*/38function sortByOrder(collection, iteratees, orders, guard) {39if (collection == null) {40return [];41}42if (guard && isIterateeCall(iteratees, orders, guard)) {43orders = null;44}45if (!isArray(iteratees)) {46iteratees = iteratees == null ? [] : [iteratees];47}48if (!isArray(orders)) {49orders = orders == null ? [] : [orders];50}51return baseSortByOrder(collection, iteratees, orders);52}5354module.exports = sortByOrder;555657