Files
lodash/sortedIndexOf.js
John-David Dalton 7293d39642 Bump to v4.1.0.
2016-01-29 01:14:13 -08:00

31 lines
772 B
JavaScript

define(['./_baseSortedIndex', './eq'], function(baseSortedIndex, eq) {
/**
* This method is like `_.indexOf` except that it performs a binary
* search on a sorted `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
* _.sortedIndexOf([1, 1, 2, 2], 2);
* // => 2
*/
function sortedIndexOf(array, value) {
var length = array ? array.length : 0;
if (length) {
var index = baseSortedIndex(array, value);
if (index < length && eq(array[index], value)) {
return index;
}
}
return -1;
}
return sortedIndexOf;
});