mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add createSortedIndex.
This commit is contained in:
@@ -2893,8 +2893,7 @@
|
|||||||
* @private
|
* @private
|
||||||
* @param {Array} array The sorted array to inspect.
|
* @param {Array} array The sorted array to inspect.
|
||||||
* @param {*} value The value to evaluate.
|
* @param {*} value The value to evaluate.
|
||||||
* @param {boolean} [retHighest] Specify returning the highest, instead
|
* @param {boolean} [retHighest] Specify returning the highest qualified index.
|
||||||
* of the lowest, index at which a value should be inserted into `array`.
|
|
||||||
* @returns {number} Returns the index at which `value` should be inserted
|
* @returns {number} Returns the index at which `value` should be inserted
|
||||||
* into `array`.
|
* into `array`.
|
||||||
*/
|
*/
|
||||||
@@ -2927,8 +2926,7 @@
|
|||||||
* @param {Array} array The sorted array to inspect.
|
* @param {Array} array The sorted array to inspect.
|
||||||
* @param {*} value The value to evaluate.
|
* @param {*} value The value to evaluate.
|
||||||
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} iteratee The function invoked per iteration.
|
||||||
* @param {boolean} [retHighest] Specify returning the highest, instead
|
* @param {boolean} [retHighest] Specify returning the highest qualified index.
|
||||||
* of the lowest, index at which a value should be inserted into `array`.
|
|
||||||
* @returns {number} Returns the index at which `value` should be inserted
|
* @returns {number} Returns the index at which `value` should be inserted
|
||||||
* into `array`.
|
* into `array`.
|
||||||
*/
|
*/
|
||||||
@@ -3663,6 +3661,22 @@
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {boolean} [retHighest] Specify returning the highest qualified index.
|
||||||
|
* @returns {Function} Returns the new index function.
|
||||||
|
*/
|
||||||
|
function createSortedIndex(retHighest) {
|
||||||
|
return function(array, value, iteratee, thisArg) {
|
||||||
|
var func = getCallback(iteratee);
|
||||||
|
return (func === baseCallback && iteratee == null)
|
||||||
|
? binaryIndex(array, value, retHighest)
|
||||||
|
: binaryIndexBy(array, value, func(iteratee, thisArg, 1), retHighest);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that either curries or invokes `func` with optional
|
* Creates a function that either curries or invokes `func` with optional
|
||||||
* `this` binding and partially applied arguments.
|
* `this` binding and partially applied arguments.
|
||||||
@@ -5377,12 +5391,7 @@
|
|||||||
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
|
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
|
||||||
* // => 1
|
* // => 1
|
||||||
*/
|
*/
|
||||||
function sortedIndex(array, value, iteratee, thisArg) {
|
var sortedIndex = createSortedIndex();
|
||||||
var func = getCallback(iteratee);
|
|
||||||
return (func === baseCallback && iteratee == null)
|
|
||||||
? binaryIndex(array, value)
|
|
||||||
: binaryIndexBy(array, value, func(iteratee, thisArg, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `_.sortedIndex` except that it returns the highest
|
* This method is like `_.sortedIndex` except that it returns the highest
|
||||||
@@ -5404,12 +5413,7 @@
|
|||||||
* _.sortedLastIndex([4, 4, 5, 5], 5);
|
* _.sortedLastIndex([4, 4, 5, 5], 5);
|
||||||
* // => 4
|
* // => 4
|
||||||
*/
|
*/
|
||||||
function sortedLastIndex(array, value, iteratee, thisArg) {
|
var sortedLastIndex = createSortedIndex(true);
|
||||||
var func = getCallback(iteratee);
|
|
||||||
return (func === baseCallback && iteratee == null)
|
|
||||||
? binaryIndex(array, value, true)
|
|
||||||
: binaryIndexBy(array, value, func(iteratee, thisArg, 1), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a slice of `array` with `n` elements taken from the beginning.
|
* Creates a slice of `array` with `n` elements taken from the beginning.
|
||||||
|
|||||||
Reference in New Issue
Block a user