Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / sortedIndexOf.js
1 var baseSortedIndex = require('./internal/baseSortedIndex'),
2     eq = require('./eq');
3
4 /**
5  * This method is like `_.indexOf` except that it performs a binary
6  * search on a sorted `array`.
7  *
8  * @static
9  * @memberOf _
10  * @category Array
11  * @param {Array} array The array to search.
12  * @param {*} value The value to search for.
13  * @returns {number} Returns the index of the matched value, else `-1`.
14  * @example
15  *
16  * _.sortedIndexOf([1, 1, 2, 2], 2);
17  * // => 2
18  */
19 function sortedIndexOf(array, value) {
20   var length = array ? array.length : 0;
21   if (length) {
22     var index = baseSortedIndex(array, value);
23     if (index < length && eq(array[index], value)) {
24       return index;
25     }
26   }
27   return -1;
28 }
29
30 module.exports = sortedIndexOf;