|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
762 bytes
|
| Line | |
|---|
| 1 | var baseSortedIndex = require('./_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 | * @since 4.0.0
|
|---|
| 11 | * @category Array
|
|---|
| 12 | * @param {Array} array The array to inspect.
|
|---|
| 13 | * @param {*} value The value to search for.
|
|---|
| 14 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 15 | * @example
|
|---|
| 16 | *
|
|---|
| 17 | * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
|
|---|
| 18 | * // => 1
|
|---|
| 19 | */
|
|---|
| 20 | function sortedIndexOf(array, value) {
|
|---|
| 21 | var length = array == null ? 0 : array.length;
|
|---|
| 22 | if (length) {
|
|---|
| 23 | var index = baseSortedIndex(array, value);
|
|---|
| 24 | if (index < length && eq(array[index], value)) {
|
|---|
| 25 | return index;
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 | return -1;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | module.exports = sortedIndexOf;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.