Sha256: dae51caf61aa9de010814e38c7944d18d0d0152be56997e2cf6ba714681de31a

Contents?: true

Size: 1.39 KB

Versions: 26

Compression:

Stored size: 1.39 KB

Contents

var baseSortedIndexBy = require('./_baseSortedIndexBy'),
    identity = require('./identity'),
    isSymbol = require('./isSymbol');

/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = 4294967295,
    HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;

/**
 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
 * performs a binary search of `array` to determine the index at which `value`
 * should be inserted into `array` in order to maintain its sort order.
 *
 * @private
 * @param {Array} array The sorted array to inspect.
 * @param {*} value The value to evaluate.
 * @param {boolean} [retHighest] Specify returning the highest qualified index.
 * @returns {number} Returns the index at which `value` should be inserted
 *  into `array`.
 */
function baseSortedIndex(array, value, retHighest) {
  var low = 0,
      high = array ? array.length : low;

  if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
    while (low < high) {
      var mid = (low + high) >>> 1,
          computed = array[mid];

      if (computed !== null && !isSymbol(computed) &&
          (retHighest ? (computed <= value) : (computed < value))) {
        low = mid + 1;
      } else {
        high = mid;
      }
    }
    return high;
  }
  return baseSortedIndexBy(array, value, identity, retHighest);
}

module.exports = baseSortedIndex;

Version data entries

26 entries across 5 versions & 3 rubygems

Version Path
minimum_viable_product-0.0.11 test/dummy/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.3 node_modules/lodash/_baseSortedIndex.js
blackboard-3.1.9 lib/site_template/node_modules/sass-graph/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.2 node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-helper-function-name/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-helper-get-function-arity/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-helper-hoist-variables/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-helper-optimise-call-expression/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-helper-regex/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-helper-replace-supers/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-es2015-block-scoping/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-es2015-classes/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-es2015-duplicate-keys/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-core/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-es2015-modules-commonjs/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-es2015-parameters/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-es2015-shorthand-properties/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-es2015-sticky-regex/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-regenerator/node_modules/lodash/_baseSortedIndex.js
babel-schmooze-sprockets-0.1.1 node_modules/babel-plugin-transform-strict-mode/node_modules/lodash/_baseSortedIndex.js