mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +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;
|
high = array ? array.length : low;
|
||||||
|
|
||||||
value = iteratee(value);
|
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) {
|
while (low < high) {
|
||||||
var mid = (low + high) >>> 1,
|
var mid = (low + high) >>> 1,
|
||||||
computed = iteratee(array[mid]),
|
computed = iteratee(array[mid]);
|
||||||
setLow = retHighest ? (computed <= value) : (computed < value);
|
|
||||||
|
|
||||||
if (hintNum && typeof computed != 'undefined') {
|
if (valIsNaN) {
|
||||||
computed = +computed;
|
var setLow = computed === computed;
|
||||||
setLow = computed != computed || setLow;
|
} else if (valIsUndef) {
|
||||||
|
setLow = computed === computed && typeof computed != 'undefined';
|
||||||
|
} else {
|
||||||
|
setLow = retHighest ? (computed <= value) : (computed < value);
|
||||||
}
|
}
|
||||||
if (setLow) {
|
if (setLow) {
|
||||||
low = mid + 1;
|
low = mid + 1;
|
||||||
|
|||||||
24
test/test.js
24
test/test.js
@@ -9996,21 +9996,21 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should align with `_.sortBy`', 8, function() {
|
test('`_.' + methodName + '` should align with `_.sortBy`', 8, function() {
|
||||||
var array = [NaN, 1, 2, {}, NaN, undefined];
|
var expected = [1, 2, {}, undefined, NaN, NaN];
|
||||||
deepEqual(_.sortBy(array), array);
|
|
||||||
strictEqual(func(array, 3), 5);
|
|
||||||
|
|
||||||
array = [1, 2, NaN, {}, NaN, undefined];
|
deepEqual(_.sortBy([NaN, 1, 2, {}, NaN, undefined]), expected);
|
||||||
deepEqual(_.sortBy(array), array);
|
strictEqual(func(expected, 3), 2);
|
||||||
strictEqual(func(array, 3), 5);
|
|
||||||
|
|
||||||
array = [NaN, '1', '2', {}, NaN, undefined];
|
deepEqual(_.sortBy([1, 2, NaN, {}, NaN, undefined]), expected);
|
||||||
deepEqual(_.sortBy(array), array);
|
strictEqual(func(expected, 3), 2);
|
||||||
strictEqual(func(array, '3'), 3);
|
|
||||||
|
|
||||||
array = ['1', '2', NaN, {}, NaN, undefined];
|
expected = ['1', '2', {}, undefined, NaN, NaN];
|
||||||
deepEqual(_.sortBy(array), array);
|
|
||||||
strictEqual(func(array, '3'), 2);
|
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() {
|
test('`_.' + methodName + '` should support arrays larger than `Math.pow(2, 31) - 1`', 1, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user