Last active
September 20, 2021 22:26
-
-
Save ArtemRomanovsky/64889e9e5523507d8a45cbd6f6e71754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function indexEqualsValue(a) { | |
let left = 0; | |
let right = a.length - 1; | |
let mid; | |
while (left != right) { | |
mid = Math.floor(((right - left) / 2) + left); | |
if (mid <= a[mid]) { | |
right = mid; | |
} else { | |
left = mid + 1; | |
} | |
} | |
return left == a[left] ? left : -1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment