Realign baseSortedIndex with _.sortBy.

This commit is contained in:
John-David Dalton
2014-09-05 09:25:48 -07:00
parent fc018691e5
commit 13022a6bb0
2 changed files with 22 additions and 19 deletions

View File

@@ -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;

View File

@@ -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() {