MCPcopy Index your code
hub / github.com/nodejs/node / binarySearchKey

Function binarySearchKey

test/fixtures/snapshot/typescript.js:1378–1399  ·  view source on GitHub ↗

* Performs a binary search, finding the index at which an object with `key` occurs in `array`. * If no such index is found, returns the 2's-complement of first index at which * `array[index]` exceeds `key`. * @param array A sorted array whose first element must be no larger than numbe

(array, key, keySelector, keyComparer, offset)

Source from the content-addressed store, hash-verified

1376 * @param offset An offset into `array` at which to start the search.
1377 */
1378 function binarySearchKey(array, key, keySelector, keyComparer, offset) {
1379 if (!some(array)) {
1380 return -1;
1381 }
1382 var low = offset || 0;
1383 var high = array.length - 1;
1384 while (low <= high) {
1385 var middle = low + ((high - low) >> 1);
1386 var midKey = keySelector(array[middle], middle);
1387 switch (keyComparer(midKey, key)) {
1388 case -1 /* Comparison.LessThan */:
1389 low = middle + 1;
1390 break;
1391 case 0 /* Comparison.EqualTo */:
1392 return middle;
1393 case 1 /* Comparison.GreaterThan */:
1394 high = middle - 1;
1395 break;
1396 }
1397 }
1398 return ~low;
1399 }
1400 ts.binarySearchKey = binarySearchKey;
1401 function reduceLeft(array, f, initial, start, count) {
1402 if (array && array.length > 0) {

Callers 1

binarySearchFunction · 0.85

Calls 1

someFunction · 0.70

Tested by

no test coverage detected