mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
add order by behaviour with array similar to get method (#4453)
* add order by behaviour with array similar to get method * remove typo for fixing orderby iteratee assignment * lint fixes * update test case * include package-lock from master * Add identity function for default iteratee
This commit is contained in:
committed by
John-David Dalton
parent
ad38dc0115
commit
5df1777477
@@ -1,8 +1,12 @@
|
||||
import baseEach from './baseEach.js'
|
||||
import baseSortBy from './baseSortBy.js'
|
||||
import baseGet from './baseGet.js'
|
||||
import compareMultiple from './compareMultiple.js'
|
||||
import isArrayLike from '../isArrayLike.js'
|
||||
|
||||
// As existing identity function is in ../test/utils.js, so defining it here, it can be moved to utils
|
||||
const identity = value => value;
|
||||
|
||||
/**
|
||||
* The base implementation of `orderBy` without param guards.
|
||||
*
|
||||
@@ -15,7 +19,12 @@ import isArrayLike from '../isArrayLike.js'
|
||||
function baseOrderBy(collection, iteratees, orders) {
|
||||
let criteriaIndex = -1
|
||||
let eachIndex = -1
|
||||
iteratees = iteratees.length ? iteratees : [(value) => value]
|
||||
iteratees = iteratees.length ? iteratees.map((iteratee) => {
|
||||
if (Array.isArray(iteratee)) {
|
||||
return (value) => baseGet(value, iteratee)
|
||||
}
|
||||
return iteratee
|
||||
}) : [identity]
|
||||
|
||||
const result = isArrayLike(collection) ? new Array(collection.length) : []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user