mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
(4.17) Short circuit sortedIndexBy methods for empty arrays (#4497)
This commit is contained in:
committed by
John-David Dalton
parent
b281ddecc4
commit
602cc3f03d
11
lodash.js
11
lodash.js
@@ -4129,11 +4129,14 @@
|
||||
* into `array`.
|
||||
*/
|
||||
function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
||||
value = iteratee(value);
|
||||
|
||||
var low = 0,
|
||||
high = array == null ? 0 : array.length,
|
||||
valIsNaN = value !== value,
|
||||
high = array == null ? 0 : array.length;
|
||||
if (high === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
value = iteratee(value);
|
||||
var valIsNaN = value !== value,
|
||||
valIsNull = value === null,
|
||||
valIsSymbol = isSymbol(value),
|
||||
valIsUndefined = value === undefined;
|
||||
|
||||
10
test/test.js
10
test/test.js
@@ -20998,6 +20998,16 @@
|
||||
assert.strictEqual(actual, 1);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should avoid calling iteratee when length is 0', function(assert) {
|
||||
var objects = [],
|
||||
iteratee = function() {
|
||||
throw new Error;
|
||||
},
|
||||
actual = func(objects, { 'x': 50 }, iteratee);
|
||||
|
||||
assert.strictEqual(actual, 0);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', function(assert) {
|
||||
assert.expect(12);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user