The Wayback Machine - https://web.archive.org/web/20170626181701/https://github.com/lodash/lodash/blob/master/orderBy.js
Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (41 sloc) 1.42 KB
import baseOrderBy from './.internal/baseOrderBy.js'
/**
* This method is like `sortBy` except that it allows specifying the sort
* orders of the iteratees to sort by. If `orders` is unspecified, all values
* are sorted in ascending order. Otherwise, specify an order of "desc" for
* descending or "asc" for ascending sort order of corresponding values.
*
* @since 4.0.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Array[]|Function[]|Object[]|string[]} [iteratees=[identity]]
* The iteratees to sort by.
* @param {string[]} [orders] The sort orders of `iteratees`.
* @returns {Array} Returns the new sorted array.
* @see reverse
* @example
*
* const users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 34 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 }
* ]
*
* // Sort by `user` in ascending order and by `age` in descending order.
* orderBy(users, ['user', 'age'], ['asc', 'desc'])
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
*/
function orderBy(collection, iteratees, orders) {
if (collection == null) {
return []
}
if (!Array.isArray(iteratees)) {
iteratees = iteratees == null ? [] : [iteratees]
}
if (!Array.isArray(orders)) {
orders = orders == null ? [] : [orders]
}
return baseOrderBy(collection, iteratees, orders)
}
export default orderBy
You can't perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.