Skip to content

Commit 29eb571

Browse files
committed
Cleanup baseOrderBy.
1 parent 5df1777 commit 29eb571

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

.internal/baseOrderBy.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import baseGet from './baseGet.js'
44
import compareMultiple from './compareMultiple.js'
55
import isArrayLike from '../isArrayLike.js'
66

7-
// As existing identity function is in ../test/utils.js, so defining it here, it can be moved to utils
8-
const identity = value => value;
7+
const identity = (value) => value
98

109
/**
1110
* The base implementation of `orderBy` without param guards.
@@ -17,20 +16,31 @@ const identity = value => value;
1716
* @returns {Array} Returns the new sorted array.
1817
*/
1918
function baseOrderBy(collection, iteratees, orders) {
19+
if (iteratees.length) {
20+
iteratees = iteratees.map((iteratee) => {
21+
if (Array.isArray(iteratee)) {
22+
return (value) => baseGet(value, iteratee)
23+
}
24+
25+
return iteratee
26+
})
27+
} else {
28+
iteratees = [identity]
29+
}
30+
2031
let criteriaIndex = -1
2132
let eachIndex = -1
22-
iteratees = iteratees.length ? iteratees.map((iteratee) => {
23-
if (Array.isArray(iteratee)) {
24-
return (value) => baseGet(value, iteratee)
25-
}
26-
return iteratee
27-
}) : [identity]
2833

2934
const result = isArrayLike(collection) ? new Array(collection.length) : []
3035

3136
baseEach(collection, (value) => {
3237
const criteria = iteratees.map((iteratee) => iteratee(value))
33-
result[++eachIndex] = { 'criteria': criteria, 'index': ++criteriaIndex, 'value': value }
38+
39+
result[++eachIndex] = {
40+
criteria,
41+
index: ++criteriaIndex,
42+
value
43+
}
3444
})
3545

3646
return baseSortBy(result, (object, other) => compareMultiple(object, other, orders))

0 commit comments

Comments
 (0)