mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Realign baseSortedIndex with _.sortBy.
This commit is contained in:
17
lodash.js
17
lodash.js
@@ -2258,17 +2258,20 @@
|
||||
high = array ? array.length : low;
|
||||
|
||||
value = iteratee(value);
|
||||
var hintNum = typeof value == 'number' ||
|
||||
(value != null && isFunction(value.valueOf) && typeof value.valueOf() == 'number');
|
||||
|
||||
var valIsNaN = value !== value,
|
||||
valIsUndef = typeof value == 'undefined';
|
||||
|
||||
while (low < high) {
|
||||
var mid = (low + high) >>> 1,
|
||||
computed = iteratee(array[mid]),
|
||||
setLow = retHighest ? (computed <= value) : (computed < value);
|
||||
computed = iteratee(array[mid]);
|
||||
|
||||
if (hintNum && typeof computed != 'undefined') {
|
||||
computed = +computed;
|
||||
setLow = computed != computed || setLow;
|
||||
if (valIsNaN) {
|
||||
var setLow = computed === computed;
|
||||
} else if (valIsUndef) {
|
||||
setLow = computed === computed && typeof computed != 'undefined';
|
||||
} else {
|
||||
setLow = retHighest ? (computed <= value) : (computed < value);
|
||||
}
|
||||
if (setLow) {
|
||||
low = mid + 1;
|
||||
|
||||
24
test/test.js
24
test/test.js
@@ -9996,21 +9996,21 @@
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should align with `_.sortBy`', 8, function() {
|
||||
var array = [NaN, 1, 2, {}, NaN, undefined];
|
||||
deepEqual(_.sortBy(array), array);
|
||||
strictEqual(func(array, 3), 5);
|
||||
var expected = [1, 2, {}, undefined, NaN, NaN];
|
||||
|
||||
array = [1, 2, NaN, {}, NaN, undefined];
|
||||
deepEqual(_.sortBy(array), array);
|
||||
strictEqual(func(array, 3), 5);
|
||||
deepEqual(_.sortBy([NaN, 1, 2, {}, NaN, undefined]), expected);
|
||||
strictEqual(func(expected, 3), 2);
|
||||
|
||||
array = [NaN, '1', '2', {}, NaN, undefined];
|
||||
deepEqual(_.sortBy(array), array);
|
||||
strictEqual(func(array, '3'), 3);
|
||||
deepEqual(_.sortBy([1, 2, NaN, {}, NaN, undefined]), expected);
|
||||
strictEqual(func(expected, 3), 2);
|
||||
|
||||
array = ['1', '2', NaN, {}, NaN, undefined];
|
||||
deepEqual(_.sortBy(array), array);
|
||||
strictEqual(func(array, '3'), 2);
|
||||
expected = ['1', '2', {}, undefined, NaN, NaN];
|
||||
|
||||
deepEqual(_.sortBy([NaN, '1', '2', {}, NaN, undefined]), expected);
|
||||
strictEqual(func(expected, '3'), 2);
|
||||
|
||||
deepEqual(_.sortBy(['1', '2', NaN, {}, NaN, undefined]), expected);
|
||||
strictEqual(func(expected, '3'), 2);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should support arrays larger than `Math.pow(2, 31) - 1`', 1, function() {
|
||||
|
||||
Reference in New Issue
Block a user