CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
_baseSortedIndex.js43 linesDownload Raw Back to lodash
1var baseSortedIndexBy = require('./_baseSortedIndexBy'),2    identity = require('./identity'),3    isSymbol = require('./isSymbol');4 5/** Used as references for the maximum length and index of an array. */6var MAX_ARRAY_LENGTH = 4294967295,7    HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;8 9/**10 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which11 * performs a binary search of `array` to determine the index at which `value`12 * should be inserted into `array` in order to maintain its sort order.13 *14 * @private15 * @param {Array} array The sorted array to inspect.16 * @param {*} value The value to evaluate.17 * @param {boolean} [retHighest] Specify returning the highest qualified index.18 * @returns {number} Returns the index at which `value` should be inserted19 *  into `array`.20 */21function baseSortedIndex(array, value, retHighest) {22  var low = 0,23      high = array == null ? low : array.length;24 25  if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {26    while (low < high) {27      var mid = (low + high) >>> 1,28          computed = array[mid];29 30      if (computed !== null && !isSymbol(computed) &&31          (retHighest ? (computed <= value) : (computed < value))) {32        low = mid + 1;33      } else {34        high = mid;35      }36    }37    return high;38  }39  return baseSortedIndexBy(array, value, identity, retHighest);40}41 42module.exports = baseSortedIndex;43 
basant307/AI_Governance_Project · CoolFace