MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / sortedIndex

Function sortedIndex

MathBox/mathbox-bundle.js:40037–40052  ·  view source on GitHub ↗

* Uses a binary search to determine the smallest index at which a value * should be inserted into a given sorted array in order to maintain the sort * order of the array. If a callback is provided it will be executed for * `value` and each element of `array` to compute their sort rank

(array, value, callback, thisArg)

Source from the content-addressed store, hash-verified

40035 * // => 2
40036 */
40037 function sortedIndex(array, value, callback, thisArg) {
40038 var low = 0,
40039 high = array ? array.length : low;
40040
40041 // explicitly reference `identity` for better inlining in Firefox
40042 callback = callback ? lodash.createCallback(callback, thisArg, 1) : identity;
40043 value = callback(value);
40044
40045 while (low < high) {
40046 var mid = (low + high) >>> 1;
40047 (callback(array[mid]) < value)
40048 ? low = mid + 1
40049 : high = mid;
40050 }
40051 return low;
40052 }
40053
40054 /**
40055 * Creates an array of unique values, in order, of the provided arrays using

Callers 1

indexOfFunction · 0.85

Calls 1

callbackFunction · 0.70

Tested by

no test coverage detected