Skip to content

Instantly share code, notes, and snippets.

@ArtemRomanovsky
Last active September 20, 2021 22:26
Show Gist options
  • Save ArtemRomanovsky/64889e9e5523507d8a45cbd6f6e71754 to your computer and use it in GitHub Desktop.
Save ArtemRomanovsky/64889e9e5523507d8a45cbd6f6e71754 to your computer and use it in GitHub Desktop.
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