Skip to content

Instantly share code, notes, and snippets.

@the-mgi
Last active November 12, 2020 00:06
Show Gist options
  • Save the-mgi/b339aaed7c5c436507538e73097b2f30 to your computer and use it in GitHub Desktop.
Save the-mgi/b339aaed7c5c436507538e73097b2f30 to your computer and use it in GitHub Desktop.
function LinearSearchRecursive(array: number[], key: number, index: number = 0): number {
if (index >= array.length) {
return -1; // in case if key is not present in the given array
} else if (array[index] === key) {
return index;
}
LinearSearchRecursive(array, key, index + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment