Last active
November 12, 2020 00:06
-
-
Save the-mgi/893fa516cf3ddecf9269b476fe8eef18 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 BinarySearchRecursive(array: number[], key, startIndex: number, lastIndex: number): number { | |
const mid = Math.floor((startIndex + lastIndex) / 2); | |
if (!(startIndex <= lastIndex)) { | |
return -1; | |
} else if (key === array[mid]) { | |
return mid; | |
} else if (key < array[mid]) { | |
BinarySearchRecursive(array, key, startIndex, mid - 1); | |
} else { | |
BinarySearchRecursive(array, key, mid + 1, lastIndex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment